开发者

Insert a formula with string variables in a cell using vba

I've set a Date variable to workday -2

Im using a String to format that Date variable using format(date, "mm/yyyy")

Im trying to add this String variable into a formula im pasting into an excel cell using VBA but it adds quotations around my String variable so the formula doesnt work.

e.g Range("Z2:Z" & Lastrow).formula = "=vlookup(y2, filename_""" & Date Name & """.xlsx"

I'm currently double quot开发者_开发技巧ing my string variable within the formula as a single quote leads to an error.

Im expecting the date to show up in the formula without being surrounded by quotation marks


The triple double quotes are concatenating a double quote to your string.

Change

 Range("Z2:Z" & Lastrow).formula = "=vlookup(y2, filename_""" & Date Name & """.xlsx"

to

 Range("Z2:Z" & Lastrow).formula = "=vlookup(y2, filename_" & Date Name & ".xlsx"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜