Hi
I have spent now hours of trying to google this solution over the internet with no success. Currently I'm using macro code that writes formulas in the cells and generates results from the formulas themselves. Basic formula looks something like this:
=INDEX(zflex!AA:AA,MATCH(KHL_YM26!A:A,zflex!Z:Z,0))
Sheet KHL_YM26 being sheet A
Sheet zflex being sheet B
Up till now I been using macro codes like below
Code:
Sub Test()
'
Range("AC2").Select
ActiveCell.FormulaR1C1 = _
"=INDEX(zflex!C[-2],MATCH(KHL_YM26!C[-28],zflex!C[-3],0))"
Range("AC2").Select
Dim K6 As Long
K6 = Cells(Rows.Count, "A").End(xlUp).Row
Selection.AutoFill Destination:=Range("AC2:AC" & K6)
End Sub
This code is for one column. Now my problem is that I need to pull over data from 11 columns from sheet B to sheet A. So by my method so far I need the macro has to perform the similar task 11 times. Performing the lookup 11 times might have been ok a month ago but I have learned so much lately that I know that this approach is ridiculous. With proper VBA code, setting variables etc I bet its possible to do one lookup or match between these two sheets, get those info from those 11 cells and place them in corresponding cells on sheet A.
So the following is what I need.
MATCH lookup value is from sheet KHL_YM26 column 1
MATCH lookup array is from sheet zflex column 26
Now it should take the info from sheet zflex from following columns:
40 27 10 25 9 29 11 31 35 36 37
And place them to sheet KHL_YM26 columns in respective order:
20 29 30 31 34 35 36 37 38 39 40
Or if its visually better to understand it
zflex -----> KHL_YM26
40 -----> 20
27 -----> 29
10 -----> 30
25 -----> 31
N/A -----> N/A
N/A -----> N/A
9 -----> 34
29 -----> 35
11 -----> 36
31 -----> 37
35 -----> 38
36 -----> 39
37 -----> 40
It would be nice to know how to achieve this in an efficient way without writing them formulas in and performing unnecessary lookups. I need to do this with some more sheets it would be nice to learn how its properly done. Doing like 20 lookups in total from 3 sheets is not efficient at all.
I have attached xls with real data. Both sheets have header rows.
Any help would be extremely appreciated.
Cheers
Rain