views:

218

answers:

1

I would like to build an excel VBA program to find all the match values from a table and print the finding on a column... I tried to use vlookup but only gives me the first location that finds... and I would like all the finds.

here is an example: my table starts on cell A2

  • column A (number)
  • 0084
  • 0084
  • 0085
  • 0085
  • 0086
  • 0087

  • column B (location)

  • 12AC5
  • 16AC5
  • 02AC5
  • 06AC5
  • 01DC5
  • 11DC5

on column D I paste the values I am looking for there location..... on column F would give me all the location found that matches my request... in ascending order or any order

for example I am looking for the location of 2 numbers:

  • column D (I paste the number that I what to see there location
  • 0084
  • 0087

I expect to see the results:

  • column F(found location)
  • 12ac5
  • 12bd5
  • 16ac5

Any help with this would be very much appreciated..

Cheers, JFFC excel VBA

enter code here
A: 
TerrorAustralis
Your first part is correct...."column A" is my reference on the table and the corresponding values are on (column B)" column F" is my output... "column D" is my request...so the plan is... if I want to get the output for a few numbers I past the numbers on "column D".... it will search and match with column A... when it finds it will grab what ever is on "column B" and paste on "column F"It is same as the lookup formula... I have a number on "column D" it will lookup on "column A"... if is a match will grab the value on "column B" and print on "column F"...
I reason that lookup does not work for me is because on gives me the first matching value that finds on "column A"...it does not keeo searching for the next matching value... by the way "column D" and "column F" they don't match...."column D" is my input... "column F" is my output.... and of course "column A" and "column B" are part of the table.... Thanks for your time..Cheers JFC
The only excel way to do this is VBA. When you want more than one cell to be changed by an operation you need a macro. The macro you are after is a For Each loop on Each Range in Column A. If the cell is the value you are looking for, get the value in column B, paste it into column F, continue. Code pasted below
TerrorAustralis
VBA macro above. You can change the columns by changing the variables ending in Col, comments in the code should explain this
TerrorAustralis
Thanks a million... it scans over 14 thousand plus rows very fast ..were use to take hours and hours to do the same manually ....this is supper fantastic... thanks again.. cheers JFC
No prob, performance is about as good as i can get it, but if you want i can add a few small incremental gains for thousand column scans
TerrorAustralis
No... this is perfect... thanks again for you time...Cheers, JFC