I am receiving a 'Next without For' on one of my for each loops when there is a For each
statement. The error is highlighting the for loop for cell
' Find and delete
Dim clear As Range
For Each clear In ActiveSheet.UsedRange
If clear.Value = "TRANS_DATE" Then clear.Cells.Delete Shift:=xlShiftUp
Next clear
Dim total As Range
For Each total In ActiveSheet.UsedRange
If total.Value = "Total Amount:" Then total.Cells.Delete Shift:=xlShiftUp
Next total
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Interior.Color = Excel.XlRgbColor.rgbYellow And cell.Font.ColorIndex = RGB(255, 0, 0) Then
cell.Delete Shift:=xlShiftUp
Next cell
Dim error As Range
For Each error In ActiveSheet.UsedRange
If error.Interior.Color = Excel.XlRgbColor.rgbYellow Then
error.EntireRow.Delete Shift:=xlShiftUp
End If
Next
任何关于什么可能是错的建议将不胜感激!
整个代码:
我总是建议严格的缩进规则,因为您会更容易看到这一点。 If上的新行表示您需要End If。