英文:
Excel VBA formula with double quotes in the formula
问题
=REPLACE(B2,1,SEARCH(";",B2)+1,"")&" "&LEFT(B2,SEARCH(";",B2)-1)
Range("A2").Formula = "=REPLACE(B2,1,SEARCH(" & CHAR(34) & ";" & CHAR(34) & ",B2)+1," & CHAR(34) & "" & CHAR(34) & ")&" & CHAR(34) & " " & CHAR(34) & "&LEFT(B2,SEARCH(" & CHAR(34) & ";" & CHAR(34) & ",B2)-1)"
英文:
I am trying to use an Excel macro to insert this into a cell:
=REPLACE(B2,1,SEARCH(",",B2)+1,"")&" "&LEFT(B2,SEARCH(",",B2)-1)
I have tried surrounding each double quote with double quotes:
Range("A2").Formula = "=REPLACE(B2,1,SEARCH(""",""",B2)+1,"""")&"" ""&LEFT(B2,SEARCH(""",""",B2)-1)"
I have also tried replacing the double quotes with CHR(34). It always seems to think that I am ending the formula after the second quote.
答案1
得分: 3
有时,采用这种方法更容易管理,而不会丢失对已添加引号的计数:
Range("A2").Formula = _
Replace("=REPLACE(B2,1,SEARCH(',',B2)+1,'') & ' ' & LEFT(B2,SEARCH(',',B2)-1)", _
"'","''")
英文:
Sometimes this approach is easier to manage without losing count of how many quotes you've added around the existing quotes:
Range("A2").Formula = _
Replace("=REPLACE(B2,1,SEARCH(',',B2)+1,'') & ' ' & LEFT(B2,SEARCH(',',B2)-1)", _
"'","""")
答案2
得分: 0
我在这种情况下使用2条规则。
- 在引号内转义双引号:两个双引号直接。
- 字符串连接符始终带有前导和尾随空格。
英文:
I use 2 rules in such situations.
- Within quote escaping double quotation mark : Two double quotation marks directly.
- String concatenation sign always with leading and trailing space.
答案3
得分: 0
我需要一些数据或信息来验证您的问题,这样将更容易帮助您了解B2中的数据类型。
因此,如果没有明确的消息,我无法帮助您。
英文:
I need some data or information to verify your problem and so, It will be easier to help you with some info about what is the kind of data in B2.
So without a clear message, I can't help you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论