We help IT Professionals succeed at work.
Get Started

how to loop through and process two columns in excel

216 Views
Last Modified: 2017-03-21
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

Open in new window


If this can be done with a formula that I just drag down the 200 or so records then great.
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE