Excel VBA公式中的双引号在公式中。

huangapple go评论89阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月9日 07:20:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436281.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定