excel - VBA Loop of Vlookup with dynamic colums -
for small project want use vlookup or match in vba derive data sheet. found difficult task of google couldn't find solution.
i divided project 3 phases:
- first phase creating working vlookup in vba (can't working)
- search range needs executed (dynamic) (i think managed)
- loop through cells in table (totally stuck on "for each" statement)
i managed fetch dynamic range #firstcell , #lastcell
but i'm stuck @ loop , vlookup. want create vlookup in such way each cell x & rownumber , y columnletter & "4". vlookup needs executed firstcell lastcell.
sub match_values() ' variables dim x integer dim y integer dim firstcell integer dim lastcell integer ' range determination activesheet range("a3").select selection.end(xltoright).select firstcell = activecell.offset(1, 1).range("a1").select end activesheet lastcell = activecell.specialcells(xllastcell).select end ' each cell create vlookup on rowindex en on y columnindex loop statement ' vlookup worksheetfunction c04 = .vlookup(x, [pivot!a4:cc99], .match(y, [sheet1!a4:cc4], 0), false) end msgbox c04 end sub
thanks in advance, if need provide additional feedback please let me know.
edit, feedback uploaded example file: https://ufile.io/48evu (i'm sorry didn't see how disclose in stackoverflow)
i found way made script work.
i agree peh should more vba, works. maybe useful try's similar , makes question answered.
thanks support!
private sub match_values() ' variables dim firstcell string dim lastcell string dim sht worksheet ' range determination activesheet range("a3").select selection.end(xltoright).select activecell.offset(1, 1).range("a1").select firstcell = activecell.address end activesheet activecell.specialcells(xllastcell).select lastcell = activecell.address end dim rng range: set rng = application.range("overview!" & firstcell & ":" & lastcell) dim cel range each cel in rng.cells cel.formular1c1 = _ "=iferror(vlookup(rc1,pivot!r4c1:r100c50,match(overview!r2c,pivot!r4c1:r4c50,0),false),""error"")" next cel end sub
greetings!
Comments
Post a Comment