Need help using VBA to compare data in Excel columns, then manipulating data

S

Sam Hill

Greetings,
I am stumped so I am hoping the experts can help. I have spent many
hours trying to write code to accomplish a certain task and no matter
how I tweak it I keep running into problems. I will attempt to
explain my goal:

I have a worksheet that contains two columns of numbers (with no empty
cells in the columns) that need to be compared. It will not always be
the same two columns, so I need to be able to input which two before
the program runs. The number of rows will also vary.

For the sake of simplicity let's call these columns dataOld and
dataNew. First I need to search through dataOld and if a number is
found that is *not* contained in dataNew, the cell containing the
dataOld number as well as the two cells to the right need to be moved
into columns "I" "J" & "K" (starting at row # 1). And each time cells
are added to IJK, they need to be placed in the row under the
previously-added cells.

Now I need to take the remaining cells in dataOld and move each cell
(and the two cells to the right) into the same row that contains the
matching number in dataNew, keeping to the same columns. (In some
rows this criteria will already be met, with the matching dataOld and
dataNew cells already in the same row).

This should then leave three blank cells (the cell in dataOld and the
two cells to the right) in the same row as dataNew if there was not a
match in dataOld.

Columns IJK now need to be adjusted to the width of the data they
contain.

Error handling should be added for two scenarios: Either the user
inputs an incorrect column (in which case there would be no matches
between dataOld and dataNew), or the user inputs an invalid column
(such as inputting a number).

There is one additional problem that I need to mention: Columns
dataOld and dataNew always have errors in some of the cells (causing
the little green triangle to appear in the upper left of the cell).
My fix for this has been to copy from an empty cell, then do a "Paste
Special" with and "Add Operation" to the entire sheet. This works,
but takes some time to run, and I would like to know of any more
efficient ways to handle this.

I hope I have done a sufficient job of explaining what I need. I
won't embarrass myself by posting any of my code attempts, although
this might give some of you a nice chuckle.

Thanks in advance for any help.

S. H.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top