简体   繁体   中英

Excel VBA - concatenate string

I am trying to learn VBA and had gotten some help on how to increment my row number on a workbook that I am referencing by using CStr. On the below I am attempting to concatenate a cell on the other workbook with string 'year'. If I take out the 'year' it works fine but with 'year' added it does not work. There must be something I am doing wrong but I cannot figure it out.

Dim year As String
year = "16"
ActiveCell.FormulaR1C1 = "='[Junk Work File.xlsx]Total'!R" & CStr(r) & "C1" & year

Try using '+' instead of '&'.

    ActiveCell.FormulaR1C1 = "='[Junk Work File.xlsx]Total'!R" & CStr(r) & "C1" + year

Or

You can use Concatenate function

    ActiveCell.FormulaR1C1 = Concatenate("='[Junk Work File.xlsx]Total'!R" & CStr(r) & "C1" , year)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM