Excel VBA Loop Compare

We have a macro which creates a list of contracted projects from a two dimensional array.  A user then adds an "X" to a cell one column to the left of that list to indicate which ones are in progress.  As projects are completed, they fall of the list; as new contracts come in, they are added.  Our challenge is that the "X" doesn't move each time the macro regenerates the list (because it has been manually entered).

The macro-generated list is in range C4:Dx.  We have copied the current list (and "X" column) to a parallel set of cells (I4:Kx) before we regenerate it.

I need help with the IF statement within a Do While loop that would:
a) Find an exact value match (if one exists) between Cx and Jx (like a LOOKUP function)
b) If there is a match, write the corresponding value from Ix to Bx
c) If not, set the corresponding value in column B to ""

In the attached example we have two sheets; what it is (IS sheet) and what it should be (SHOULD sheet).  In the IS sheet, the original list was copied from B4:D11 to I4:K11 and a new list was generated into C4:D12.  Since the first three rows match, everything is fine for them.  However, the fourth and fifth entries in the new list didn't exist in the old list, so the value in the B column for those rows should be "".  In contrast, because the new list is longer, there should be a corresponding "X" in B12 due to the Augusta match.

Any help is greatly appreciated.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
I wasn't sure whether you want to do it with formula or macro's..Check the Column-A of the should be column..I have done the same with macro which does what you are looking for..

M_PattonAuthor Commented:

I did want it in a macro.   If you have that I'd be most appreciative.
Saurabh Singh TeotiaCommented:
You can use the following macro..

Sub applf()

    Dim lrow As Long, lr As Long
    lrow = Cells(Cells.Rows.Count, "c").End(xlUp).Row
    lr = Cells(Cells.Rows.Count, "j").End(xlUp).Row

    Range("B4:B" & lrow).Formula = "=IF(SUMPRODUCT(($J$4:$J$" & lr & "=C4)*($I$4:$I$" & lr & "=""X""))>0,""X"","""")"
    Range("B4:B" & lrow).Value = Range("B4:B" & lrow).Value
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
M_PattonAuthor Commented:
Nice and short!  I like it!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.