0
嗨,我有這個代碼只能運行在一個工作表(sheet3),但我希望它循環其他工作簿並運行此代碼。我嘗試過使用for each循環,但它似乎不符合此代碼。我查了其他循環方法,但我真的不確定如何去做。納入工作表循環
下面是代碼
Sub DeleteCells()
Dim rng As Range, rngError As Range, delRange As Range
Dim i As Long, j As Long
On Error Resume Next
Set rng = Application.InputBox("Select cells To be deleted", Type:=8)
On Error GoTo 0
If rng Is Nothing Then Exit Sub Else rng.Delete
With Sheets("Sheet3")
For i = 1 To 7 '<~~ Loop trough columns A to G
'~~> Check if that column has any errors
On Error Resume Next
Set rngError = .Columns(i).SpecialCells(xlCellTypeFormulas, xlErrors)
On Error GoTo 0
If Not rngError Is Nothing Then
For j = 1 To 100 '<~~ Loop Through rows 1 to 100
If .Cells(j, i).Text = "#REF!" Then
'~~> Store The range to be deleted
If delRange Is Nothing Then
Set delRange = .Columns(i)
Exit For
Else
Set delRange = Union(delRange, .Columns(i))
End If
End If
Next
End If
Next
End With
'~~> Delete the range in one go
If Not delRange Is Nothing Then delRange.Delete
End Sub
omg這個作品!非常感謝!!! @布林德先知 – Niva