我尝试在excel中执行一个宏来清除A1:A100的单元格,但我只找到一个可以对一个单元格执行此操作的宏。如何让它适用于更多细胞?
Sub ClearCell()
Dim Rng As Range
Set Rng = ActiveSheet.Range("A1")
Dim i As Long
For i = 1 To 10
If Rng.Cells(i,1) = "" Then
Rng.Cells(i,1).ClearContents
End If
Next i
End Sub
答案 0 :(得分:0)
试试这个:
Sub test()
Dim Cl As Range
For Each Cl In [A1:A100]
If Cl.Value = "" Then
With Cl
.ClearFormats
.ClearContents
End With
End If
Next Cl
End Sub
答案 1 :(得分:0)
更好,试试这个:
Sub foo()
Range("A1:A100").ClearContents
Range("A1:A100").ClearFormats
End Sub