Hi. My fairly large spreadsheet has 23 columns and can have any number of rows (current one 969). I want to use VBA to delete the entire row for every row that contains a negative number in column K ($ amount)
Sub delete_row()
Dim datalastrow, x As Long
datalastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ' find the last row of data in colA
For x = datalastrow To 1 Step -1
If ActiveSheet.Range(Cells(x, 11), Cells(x, 11)) < 0 Then 'K equates to Col 11 here
Range(Cells(x, 11), Cells(x, 11)).EntireRow.Delete
End If
Next x
End Sub
Account | Company | Line | Document | Assignment | Date | Due | Terms |
| C/O | Amount | Type | |||||||||||||||||
38308 | 1130 | 1 | 910026792 | 910026792 | 12/19/2023 | 12/19/2023 | A003 | 20 | 0 | (35,789.60) | RV | |||||||||||||||||
38308 | 1130 | 1 | 98708995 | 98708995 | 3/28/2022 | 3/28/2022 | A003 | 651 | 0 | -2381.40 | RR | |||||||||||||||||
38308 | 1130 | 1 | 90018113 | 90018113 | 11/8/2023 | 11/8/2023 | A003 | 61 | 0 | (32,523.40) | RV | |||||||||||||||||
38308 | 1130 | 1 | 910057714 | 910057714 | 1/4/2024 | 1/4/2024 | A003 | 4 | 0 | (17,225.65) | RV | |||||||||||||||||
38308 | 1130 | 1 | 99379853 | 99379853 | 1/17/2023 | 1/17/2023 | A003 | 356 | 0 | (12,962.29) | RV | |||||||||||||||||
38308 | 1130 | 3 | 1400565408 | 240 | 12/1/2022 | 1/1/2023 | 0 | 372 | 0 | -26.24 | DZ |
Sub delete_row()
Dim datalastrow, x As Long
datalastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ' find the last row of data in colA
For x = datalastrow To 1 Step -1
If ActiveSheet.Range(Cells(x, 11), Cells(x, 11)) < 0 AND ActiveSheet.Range(Cells(x, 12), Cells(x, 12)) = "RV" Then 'K equates to Col 11 here
Range(Cells(x, 11), Cells(x, 11)).EntireRow.Delete
End If
Next x
End Sub
Sub Del_rows_v1()
Application.ScreenUpdating = False
If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
With Range("A1").CurrentRegion
.AutoFilter Field:=12, Criteria1:="RV"
.AutoFilter Field:=11, Criteria1:="<0"
If .Columns(1).SpecialCells(xlVisible).Count > 1 Then .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
.AutoFilter Field:=11
.AutoFilter Field:=12
End With
Application.ScreenUpdating = True
End Sub
If .Columns(1).SpecialCells(xlVisible).Count > 1 Then .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
If .Columns(1).SpecialCells(xlVisible).Count > 1 Then .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete