excel - VBA vlookup in external workbook -


i trying code working still showing errors. code to, workbook1, open workbook2 , insert vlookup function in workbook1 search values workbook1 in range workbook2 code follows:

application.screenupdating = false dim fnameandpath variant, wb workbook fnameandpath = application.getopenfilename(title:="wybierz plik kontroli rabatu") if fnameandpath = false exit sub set wb = workbooks.open(fnameandpath)  thisworkbook.activate sheets("icos").activate set lookupvalue = thisworkbook.sheets("sheet1").cells(3, 3) set rnglookuprange = wb.worksheets("sheet1").range("$a:$p")     range("c3:c300") = application.worksheetfunction.vlookup(lookupvalue, rnglookuprange, 16, false) 

what wrong in code? shows "unable vlookup property of worksheetfunction class"

thanks

there 2 problems here:

lookupvalue should not object, value, such string, double, integer. change corresponding line to

lookupvalue = thisworkbook.sheets("sheet1").cells(3, 3).value 

secondly, vlookup function returns 1 value (or #n/a). not return range. change next line like

range("c4").value = application.worksheetfunction.vlookup(lookupvalue, rnglookuprange, 16, false) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -