PDA

View Full Version : [SOLVED:] VBA - Comparing the numeric value of two cells for changes



sean.golds
07-17-2017, 07:40 AM
I have an excel spreadsheet, using only one worksheet within which I need to compare two numerical values, located 2 rows apart within the same column for a specific change in the following way (the following isn't an attempt at code, just my description of what I need):
Column 7 (G) Row 2 (B) to be compared against Column 7 (G) Row 4 (D) If Row 4 value is < Row 2, highlight in red
Then move to Column 7 (G) Row 4 (D) and compare against Column 7 (G) Row 6 (F) If Row 6 value is < Row 4, highlight in red
Repeat this process until we reach a blank row.
Any help would be appreciated.
Thanks

SamT
07-17-2017, 09:16 AM
Sub CompareAltRows()
Dim rw As Long

With Columns(7)
For rw = 2 to .Cells(Rows.Count).End(xlUp).Row - 2 Step 2
IF .Cells(rw + 2) < .Cells(rw) Then .Cells(rw + 2).Interior.ColorIndex = 3 'Change "Interior" to "Font" to color just the text.
Next
End with
End Sub

jolivanes
07-17-2017, 10:47 PM
Hi SamT
Change the comma to < In the If line?

SamT
07-18-2017, 05:07 AM
Stubid Kayboard

sean.golds
07-25-2017, 01:32 AM
Thanks guys much appreciated