troubleshooting Question

how to loop through and process two columns in excel

Avatar of Anthony Horner
Anthony Horner asked on
Microsoft ExcelVBAVisual Basic ClassicVB ScriptMicrosoft Office
8 Comments1 Solution217 ViewsLast Modified:
I’ve  two tables on a spreadsheet.  The largest (the requirements table)  with  is formatted in the following way:

Req ID | Parent Req ID | Some text column | Process Level ID

The smaller table (the parents table) with the parent requirements is just two columns:-

Parents Req ID | Process Level ID

I’ve been trying to write a script to go through each parent req ID in parent table and find requirements which have the same parent ID in the requirements table and then output the  req record Plus the parent req ID  somewhere else on the sheet where the process level ID value of the parent and the process level id of the requirement are NOT the same.

I tried to write a script (it’s been years and I’ve forgotten everything) and surprise surprise, it doesn’t work.  I didn’t even know how to output the record elsewhere that I just tried to highlight the req record!

I was trying to compare values by using + 2 etc. to get the values from the next but one column

Any pointers on where I’m going wrong would be greatly appreciated.

Sub ProduceEligNonAligned()

    'Looping through each of our output cells.
    For Each g In Range("G2:G21")
        For Each a In Range("A2:A193")
            If g.Column = a.Column + 1 Then
                If g.Column + 2 <> a.Column + 3 Then
                    a.Interior.ColorIndex = 37
                    'Exit out of this loop and move to the next output cell.
                    Exit For
                End If
            End If
            'If the columns don't match
        Next a
    Next g

End Sub

If this can be done with a formula that I just drag down the 200 or so records then great.
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros