我無法弄清楚這條線For Each c In ws.UsedRange.Cells
我不斷收到錯誤Method 'worksheet' range failed
修剪宏得到錯誤
感謝
編輯:更新
Sub trimAll()
Dim ws As Worksheets
Dim c As Range
For Each ws In WorkSheets
If ws.Name = "XXX" Or ws.Name = "YYY" Then
For Each c In ws.UsedRange.Cells
If Not (IsEmpty(c) Or IsError(c)) Then
c.Value = Trim(c.Value)
End If
Next c
End If
Next ws
End Sub
如果** XXX **和** YYY **是有效的工作表對象,那麼在代碼中應該沒有任何問題。 – L42 2014-11-24 02:51:31