我无法弄清楚这一行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
答案 0 :(得分:2)
尝试:For Each ws in Worksheets
因为Sheets集合可以包含不是工作表的内容