如何将双引号放入VBA中的字符串中?我希望通过包含双引号的VBA在单元格中插入一个if语句。这是我的代码:Worksheets("Sheet1").Range("A1").Value = "=IF(Sheet1!B1=0,"",Sheet1!B1)"由于双引号,我在插入字符串时有问题。如何处理双引号?
3 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
Worksheets("Sheet1").Range("A1").Formula = "IF(Sheet1!A1=0,"""",Sheet1!A1)"
Worksheets("Sheet1").Range("A1").Formula = "IF(Sheet1!A1=0," & CHR(34) & CHR(34) & ",Sheet1!A1)"
翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
Sub RepairFormula()Dim FormulaString As StringFormulaString = "=MID(CELL(~filename~,$A$1),FIND(~[~,CELL(~filename~,$A$1))+1,FIND(~]~, CELL(~filename~,$A$1))-FIND(~[~,CELL(~filename~,$A$1))-1)"FormulaString = Replace(FormulaString, Chr(126), Chr(34)) 'this replaces every instance of the tilde with a double quote.Range("WorkbookFileName").Formula = FormulaString
添加回答
举报
0/150
提交
取消