Consulting

Results 1 to 5 of 5

Thread: VBA - Comparing the numeric value of two cells for changes

  1. #1

    VBA - Comparing the numeric value of two cells for changes

    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

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    Last edited by SamT; 07-18-2017 at 05:08 AM. Reason: Change the comma to < In the If line
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Hi SamT
    Change the comma to < In the If line?

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Stubid Kayboard
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Thanks guys much appreciated

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •