Entering excel formula with quotations in a loop using VBA

后端 未结 1 632
你的背包
你的背包 2021-01-24 11:04

I am trying to use VBA to to insert a formula in excel that would look like the following in excel:

=BDH(C2,\"PX LAST\",F2,\"\",\"Dir=H\",\"days=w\",\"DTS=H\",\"         


        
相关标签:
1条回答
  • You should not be putting the Cells inside the formula string, and you should be using the Address property:

    formulaString = "=BDH(" & Cells(i,3).Address(False, False) & ",""PX LAST""," & Cells(i,6).Address(False, False) & ","""",""Dir=H"",""days=w"",""DTS=H"",""cols=1;rows=1"")"
    

    However what you actually want is switching to the R1C1 notation:

    formulaStringR1C1 = "=BDH(RC3,""PX LAST"",RC6,"""",""Dir=H"",""days=w"",""DTS=H"",""cols=1;rows=1"")"
    

    and then using

    Cells(i,8).FormulaR1C1 = formulaStringR1C1
    
    0 讨论(0)
提交回复
热议问题