forensic93
New Member
- Joined
- Jan 14, 2020
- Messages
- 16
- Office Version
- 2016
- Platform
- Windows
Hi all,
I have a workbook in which i have multiple sheets currently maxed out on line limits.
Deleting the lines manually is taking forever so i wrote a macro which will delete any line in which columns B, C, D, F, G and I have a 0 in them.
I'm getting an issue where the code only goes to the last sheet and deletes every second row meeting that criteria only up to row 400.
Would someone be able to explain why this is happening and possible fix for it?
I have a workbook in which i have multiple sheets currently maxed out on line limits.
Deleting the lines manually is taking forever so i wrote a macro which will delete any line in which columns B, C, D, F, G and I have a 0 in them.
I'm getting an issue where the code only goes to the last sheet and deletes every second row meeting that criteria only up to row 400.
Would someone be able to explain why this is happening and possible fix for it?
VBA Code:
sheetNumber = 1
rowNumber = 2 ' first row is headings
Counter = 400
For i = 1 To Counter
If (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 2).Value = 0) And (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 3).Value = 0) And (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 4).Value = 0) And (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 5).Value = 0) And (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 6).Value = 0) And (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 7).Value = 0) And (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 8).Value = 0) And (Sheets("Sheet" & sheetNumber).Cells(rowNumber, 9).Value = 0) Then
Rows("rowNumber").EntireRow.Delete
End If
''''''''''''''''''''''''''''''''''''''''''''''
' Change to next sheet
''''''''''''''''''''''''''''''''''''''''''''''
rowNumber = rowNumber + 1
If rowNumber > 990002 Then
rowNumber = 2
sheetNumber = sheetNumber + 1
End If
Next