Hello!
I just recently moved into a new job at work and one of my first duties is creating macros. I am woefully inept at this so far and for the most part have been reverse engineering recorded macros to learn.
My problem I am looking at is that I have an array of six codes in COLUMN B that indicate reversals of payments. Once I see one of these codes in this column I need the macro to check the same row for a value in COLUMN C once it finds that value it needs to move up a row and check to see if the same value is in that row. If all three values are true it needs to delete both columns.
Column A (DATES) Column B (CODES) Column C (PAYMENTS)
1/1/1990 1(Valid pmt code) $200
1/1/1990 REV(reversal code) $200
1/1/1990 1 $200
1/1/1990 1 $523
1/1/1990 6(also a reversal code) $523
In this example it would delete rows 1,2,4,5 but leave row 3 intact.
*This is the code I am currently attempting to use.*
Sub Formatting()
'THIS IS THE CONDITIONAL FORMATTING TO CHECK FOR REVERSALS'
Dim Firstrow As Long
Dim LastRow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim Cell As Range
Dim Cell1 As String
Dim Cell2 As String
Dim Cell3 As String
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
'We select the sheet so we can change the window view
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row + 1
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = LastRow To Firstrow Step -1
'We check the values in the B column'
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
Cell1 = .Cells(Lrow, "A").Value
Cell2 = .Cells(Lrow, "B").Value
Cell3 = .Cells(Lrow, "C").Value
If Trim(.Cells(Lrow, "B").Value) = "REV" And .Cells(Lrow - 1, "C").Value = .Cells(Lrow, "C").Value Then
Rows(Lrow).EntireRow.Delete
Rows(Lrow - 1).EntireRow.Delete
End If
End If
End With
Next Lrow
End With
Bookmarks