我有清除4個不同頁面上不同範圍的未受保護單元格的內容的代碼。這是緩慢的,並給我一個「聯盟'全球失敗的方法」。有什麼建議麼?我的代碼被附加以下按鈕清除未受保護的單元格太慢/無法正常工作
Sub ClearAllUnLocked()
Application.ScreenUpdating = False
Dim r As Range, rKlear As Range
Set rclear = Nothing
For Each r In ThisWorkbook.Worksheets("A").Range("F7:AA832")
If r.Locked = False Then
If rKlear Is Nothing Then
Set rKlear = r
Else
Set rKlear = Union(rKlear, r)
End If
End If
Next r
rKlear.ClearContents
For Each r In ThisWorkbook.Worksheets("B").Range("D7:Y806")
If r.Locked = False Then
If rKlear Is Nothing Then
Set rKlear = r
Else
Set rKlear = Union(rKlear, r)
End If
End If
Next r
rKlear.ClearContents
For Each r In ThisWorkbook.Worksheets("E").Range("F7:AA855")
If r.Locked = False Then
If rKlear Is Nothing Then
Set rKlear = r
Else
Set rKlear = Union(rKlear, r)
End If
End If
Next r
rKlear.ClearContents
For Each r In ThisWorkbook.Worksheets("X").Range("F7:AA3006")
If r.Locked = False Then
If rKlear Is Nothing Then
Set rKlear = r
Else
Set rKlear = Union(rKlear, r)
End If
End If
Next r
rKlear.ClearContents
Application.ScreenUpdating = True
End Sub
感謝
嘗試設置rKlear =每個表單循環前都沒有。並且我相信rclear與其他代碼不匹配rklear。 – TJYen
要做的第一件事就是將'rclear'改爲'rKlear'。 (把'Option Explicit'作爲每個代碼模塊的第一行 - 它會幫助檢測錯別字。)我懷疑這是否能解決你的問題,但它可能會阻止未來的問題。 – YowE3K