need a macro to compare data ranges in columns

September 26, 2012 at 12:53:52
Specs: Windows XP
Hey Gang! I have two ranges of package numbers in an Excel spreadsheet. Column A lists what the corp. office says we should have. In column B is what the warehousing company says we have. I want to compare the two lists and insert a cell in column B where the number is missing. I tried below, but all it did was insert two extra rows at the top of the list and nothing else.

lastRw = Range("A" & Rows.Count).End(xlUp).Row
For rw = 1 To lastRw
If Cells(rw + 1, 2) <> Cells(rw, 2) Then
Cells(rw + 1, 2).EntireRow.Insert
Cells(rw + 1, 1) = Cells(rw - 1, 1)
rw = rw + 2
End If
End Sub

Any info would be greatly appreciated.


See More: need a macro to compare data ranges in columns

Report •

September 26, 2012 at 17:33:38
First, a posting tip...

Please click on the blue line at the end of this post and read the instructions on how to post example data and VBA code in this forum.

Second, without any example data, we can't tell you why your code is not giving you the results you want. We have nothing to test it against. We don't need a lot of data, just enough to show us what you are starting with and the desired output based on that data.

All I can say at this point is that I don't see anything in the code that compares Column A to Column B. The only "comparison" instruction I see is this one:

If Cells(rw + 1, 2) <> Cells(rw, 2) Then

That line compares a cell in Column B to the cell above it. That doesn't sound like what you are trying to do, but again, without some example data, I don't really know what you are trying to do.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question