简体   繁体   中英

Vlookup and match excel function to VBA?

=VLOOKUP($I13,Data!$B$13:$XFD$1048576,MATCH(M$10,Data!$B$11:$XFD$11,0),FALSE)

This is the function I am trying to translate to VBA to increase efficiency.

The purpose is to link the date on page to another page ( I13 ) and then match the heading from one page to another ( M10 ) so that when I enter a new header it pulls the data automatically from a sheet full with data. That is what the above function did how do i convert to VBA ?

Thank you

I was working on this function but not succeed,

1   2   3   4           1   2   3   4

Yash 123 255 1000 2000 Yash 123 255 1000 2000 ABC 234 456 5000 8000 ABC 234 456 5000 8000 XYZ 567 998 12000 18000 XYZ 567 998 12000 18000 XYZ 567 998 12000 18000 Yash 123 255 1000 2000 ABC 234 456 5000 8000 Yash 123 255 1000 2000 XYZ 567 998 12000 18000 XYZ 567 998 12000 18000

Sub yash()
r = 2
Do While Cells(r, 7) <> ""
Cells(r, 8) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 8), Range("A1:E1"), 0), 0)
Cells(r, 9) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 9), Range("A1:E1"), 0), 0)
Cells(r, 10) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 10), Range("A1:E1"), 0), 0)
Cells(r, 11) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 11), Range("A1:E1"), 0), 0)
r = r + 1
Loop
End Sub

to demonstrate it please copy all and paste in cell("A1") from line 2 in this comment.

enter image description here

Sub yash()
r = 2
Do While Cells(r, 7) <> ""
Cells(r, 8) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 8), Range("A1:E1"), 0), 0)
Cells(r, 9) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 9), Range("A1:E1"), 0), 0)
Cells(r, 10) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 10), Range("A1:E1"), 0), 0)
Cells(r, 11) = WorksheetFunction.VLookup(Cells(r, 7), Range("A2:E4"), WorksheetFunction.Match(Cells(1, 11), Range("A1:E1"), 0), 0)
r = r + 1
Loop
End Sub

to demonstrate it please copy all and paste in cell("A1") from line 2 in this comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM