excel vba - Vlookup error message when comparing 2 opened workbooks -


i have problem code below:

code:

sub cpt_click()       dim cptbook, prbook workbook     dim cptsheet, prsheet worksheet     dim cptrange range     dim myresult, lookvalue string       set prbook = thisworkbook     set prsheet = prbook.worksheets("implementation")     set cptbook = workbooks.open("cpt.xlsx", readonly:=true)     set cptsheet = cptbook.worksheets(2)     set cptrange = cptsheet.range("g4:dy300")      lookvalue = prsheet.range("u18").value   'returns correct value     myresult = application.worksheetfunction.vlookup(lookvalue, cptrange, 2, false)     msgbox myresult   end sub 

when click on button, famous: "unable vlookup property of worksheetfunction class" error message.

i have tried , when typing vlookup function inside sheet, correct value - value i'm looking (lookvalue) in cptsheet within cptrange.

any thoughts?

thanks in advance.

you need set cptrange's external attribute of address property true. use evaluate method this:

myresult = evaluate("vlookup(""" & lookvalue & """," & cptrange.address(external:=true) & ",2,false)") 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -