有个高手写了个一次性选定所有未锁定单元格的代码,你可以试试。
Sub bb()
Dim mrg As Range, K As Integer
For Each mrg In ActiveSheet.UsedRange
If mrg.Locked = False Then
K = K + 1
If K = 1 Then mrg.Select
Union(Selection, mrg).Select
End If
Next mrg
End Sub
我师傅给了我个另类的代码,可以试试:
Sub test()
Dim vUnlocked As Variant
Dim rngUnlocked As Range
With ActiveSheet
If .ProtectContents = True Then .Unprotect
vUnlocked = .UsedRange
.UsedRange.ClearContents
.Protect
On Error Resume Next
.UsedRange.Value = 1
.Unprotect
Set rngUnlocked = .UsedRange.SpecialCells(xlCellTypeConstants)
.UsedRange = vUnlocked
rngUnlocked.Select
End With
selection.clearcontents
End Sub
Sub test()
Dim vUnlocked As Variant
Dim rngUnlocked As Range
With ActiveSheet
.Unprotect Password:="abcd" '<<<<这好象要加入解保护??
If .ProtectContents = True Then .Unprotect
vUnlocked = .UsedRange
.UsedRange.ClearContents
.Protect
On Error Resume Next
.UsedRange.Value = 1
.Unprotect
Set rngUnlocked = .UsedRange.SpecialCells(xlCellTypeConstants)
.UsedRange = vUnlocked
rngUnlocked.Select
.Protect Password:="abcd" '<<<< 这好象要加入加保护???
End With
Selection.ClearContents
End Sub