excel - Using a file location in a VLOOKUP issue -
i got code answer on here , better way doing because can select pulling file from. seems can't file name correct in vlookup? error 1004 right after vlookup. maybe there else wrong. copied code replaced needed need pair of eyes. in advance.
dim x string dim lnewbracketlocation long x = application.getopenfilename( _ filefilter:="excel files (*.xls*),*.xls*", _ title:="choose previous quarter's file", multiselect:=false) msgbox "you selected " & x 'find last instance in string of path separator "\" lnewbracketlocation = instrrev(x, application.pathseparator) 'edit string suit vlookup formula - insert "[" x = left$(x, lnewbracketlocation) & "[" & right$(x, len(x) - lnewbracketlocation) range("v2").select activecell.formular1c1 = "=vlookup($e2,'" & x & "]file_2017072732'!$b$5:$ap$9486,18,false)" ' error 1004 selection.autofill destination:=range("v2:v177") range("v2:v177").select
when point shows x equal "c:\name\name\name\[filename.xlsx"
.
is format should be?
the issue not value of x
, looks in valid format.
the problem lies assigning formula, written using a1
notation, cell using formular1c1
property.
change
activecell.formular1c1 = "=vlookup($e2,'" & x & "]file_2017072732'!$b$5:$ap$9486,18,false)"
to either
activecell.formula = "=vlookup($e2,'" & x & "]file_2017072732'!$b$5:$ap$9486,18,false)"
or
activecell.formular1c1 = "=vlookup(rc5,'" & x & "]file_2017072732'!r5c2:r9486c42,18,false)"
and should ok.
Comments
Post a Comment