I wrote some VBA code that is meant to delete a row based on the value of a cell.
Const VENDRO_FIELD = 4
Dim rDataTable As Range
Set rDataTable = Range(Cells(1, 1), Cells(1, 1).End(xlToRight).End(xlDown))
Dim sCurrentRecord As Single
Dim sNumberOfRecords As Single
sNumberOfRecords = rDataTable.Rows.Count
Dim tVendor As String
For sCurrentRecord = 1 To sNumberOfRecords
tVendor = rDataTable.Cells(sCurrentRecord, VENDOR_FIELD)
If tVendor = "MTR" Then
Selection.Rows(sCurrentRecord).EntireRow.Delete
End If
Next sCurrentRecord
The cells containing the vendor are in column D, which is why the const is set to 4. But whenever I run this code it is deleting the wrong row. I don't know how it's selecting the row it decides to delete, so right now it seems random to me.
Does anyone know why it's not deleting the row that should be selected based off sCurrentRecord?