如何在vba中的字符串中加上双引号? [英] How do I put double quotes in a string in vba?
本文介绍了如何在vba中的字符串中加上双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
工作表(Sheet1)。范围(A1)。Value == IF(Sheet1!B1 = 0,,Sheet1!B1)
由于双引号,我在插入字符串时遇到问题。我如何处理双引号?
解决方案
我发现最简单的方法是加倍报价来处理报价。 / p>
工作表(Sheet1)。范围(A1)。Formula =IF(Sheet1!A1 = 0, ,Sheet1!A1)
有些人喜欢使用CHR(34)*: p>
工作表(Sheet1)。范围(A1)。Formula =IF(Sheet1!A1 = 0,& CHR(34)& CHR(34)&,Sheet1!A1)
*注:CHAR()用作Excel单元格公式,例如在单元格中写= CHAR(34),但是对于使用CHR()函数的VBA代码。
I want to insert an if statement in a cell through vba which includes double quotes.
Here is my code:
Worksheets("Sheet1").Range("A1").Value = "=IF(Sheet1!B1=0,"",Sheet1!B1)"
Due to double quotes I am having issues with inserting the string. How do I handle double quotes?
解决方案
I find the easiest way is to double up on the quotes to handle a quote.
Worksheets("Sheet1").Range("A1").Formula = "IF(Sheet1!A1=0,"""",Sheet1!A1)"
Some people like to use CHR(34)*:
Worksheets("Sheet1").Range("A1").Formula = "IF(Sheet1!A1=0," & CHR(34) & CHR(34) & ",Sheet1!A1)"
*Note: CHAR() is used as an Excel cell formula, e.g. writing "=CHAR(34)" in a cell, but for VBA code you use the CHR() function.
这篇关于如何在vba中的字符串中加上双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文