Hi,
My data set is >320,000 rows deep, 45 columns. There is column headed by "Record Status Code" populated by "1" or "3". Another column "Transaction ID" has a number in string format.
My instructions were:
"9. All claims with RecordStatus = 3 are reversals. We need to remove them, along with the original claim they reversed. To find the original claim, look at the Transaction ID for the reversal, and replace the last digit (1) with a 0."
In other words, for every row with Record Status Code = "3", also find the row containing Transaction ID with altered last digit, and delete both rows.
I wrote a code that seems to work. However, it takes way too long. Is there an alternative/optimized method?
My data set is >320,000 rows deep, 45 columns. There is column headed by "Record Status Code" populated by "1" or "3". Another column "Transaction ID" has a number in string format.
My instructions were:
"9. All claims with RecordStatus = 3 are reversals. We need to remove them, along with the original claim they reversed. To find the original claim, look at the Transaction ID for the reversal, and replace the last digit (1) with a 0."
In other words, for every row with Record Status Code = "3", also find the row containing Transaction ID with altered last digit, and delete both rows.
I wrote a code that seems to work. However, it takes way too long. Is there an alternative/optimized method?
Code:
Sub Step9()
Dim x As String, y As String
Dim a As Long
Dim Tcol As Range, Rcol As Range
Application.ScreenUpdating = False
With ActiveWorkbook.ActiveSheet
Set Rcol = .Columns(Application.WorksheetFunction.Match("Record Status Code", Range("1:1"), 0))
Set Tcol = .Columns(Application.WorksheetFunction.Match("Transaction ID", Range("1:1"), 0))
Do Until Rcol.Find("3") Is Nothing
a = Application.WorksheetFunction.Match("3", Rcol, 0)
x = Tcol.Cells(a).Text
y = Left(x, Len(x) - 1) & "0"
Tcol.Find(x).EntireRow.Delete
Tcol.Find(y).EntireRow.Delete
Loop
End With
Application.ScreenUpdating = True
End Sub