VBAProIWish
Well-known Member
- Joined
- Jul 6, 2009
- Messages
- 1,027
- Office Version
- 365
- Platform
- Windows
Hello All,
I am trying to create a macro that deletes a row based on values in two columns.
Because my column positions are dynamic, they must be found by column (header) name (Customer Number, Total, Order Size)
I thought the code below would do it, but I am getting the error..."Compile Error - End if without block if"
I'm sure it's one silly thing that I just can't figure out and any help would be much appreciated!
I am trying to create a macro that deletes a row based on values in two columns.
Because my column positions are dynamic, they must be found by column (header) name (Customer Number, Total, Order Size)
I thought the code below would do it, but I am getting the error..."Compile Error - End if without block if"
I'm sure it's one silly thing that I just can't figure out and any help would be much appreciated!
VBA Code:
[B]Delete any row where the "Order Size" column is small and the "Total" column is less than $500000[/B]
Dim customerCol As Integer
Dim totalCol As Integer
Dim bigorderCol As Integer
customerCol = Application.WorksheetFunction.Match("Customer Number", Rows(1).EntireRow, 0)
totalCol = Application.WorksheetFunction.Match("Total", Rows(1).EntireRow, 0)
bigorderCol = Application.WorksheetFunction.Match("Order Size", Rows(1).EntireRow, 0)
'Select the last row of customer numbers
Cells(65536, customerCol).End(xlUp).Select
'check and loop until back at the top of the sheet
Do While ActiveCell.Row > 1
If Cells(ActiveCell.Row, totalCol).Value < 500000 _
And Cells(ActiveCell.Row, bigorderCol).Value = "Small" _
Then Cells.EntireRow.Delete
End If
ActiveCell.Offset(-1, 0).Select
Loop
End Sub