When writing string to a cell, VBA inserts extra single quotation marks

后端 未结 2 1090
北海茫月
北海茫月 2020-12-11 06:10

I am trying to write this formula using VBA:

ActiveCell.Value = \"=f(R[-1]C[0],Sheet1!\" & ColumnLetter & i & \")\"

Where Colum

相关标签:
2条回答
  • 2020-12-11 06:17

    Its the combination of R1C1 and A1 addressing. You need to pick one method and use it for both parts.
    Note that if you type =f(R[-1]C[0],Sheet1!F16) into a cell you will get an error for the same reason.

    You say you need to use R1C1 style for the first address, but (assuming this is because you don't want absolute address) you can use .Offset instead

    ActiveCell.Value = "=f(" & ActiveCell.Offset(-1, 0).Address(False, False) _
     & ",Sheet1!" & ColumnLetter & i & ")"
    
    0 讨论(0)
  • 2020-12-11 06:43

    The Apostrophe means to Excel that it should interpret it as text.

    Write it to ActiveCell.Formula. That way it is recognized as Formula.

    0 讨论(0)
提交回复
热议问题