我正在vba模块中运行循环,并使用vba函数<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
将输入到消息框中的文本写入单元格区域。
问题是当循环处理单词“ Do n't”中的撇号时,
它使撇号在单元格中不可见。
我需要在代码中进行哪些更改才能使撇号可见?
这是有问题的片段,它是有关的:
MID
答案 0 :(得分:1)
撇号是一种“隐藏代码”,用于告诉Excel它是文本。您可以在所有输出到单元格的前面加上撇号,它将正常工作:
Worksheets("Sheet1").Cells(7, CounterChase).Value = "'" & Mid(MyText, CounterTxt, 1)
答案 1 :(得分:0)
当引号到达文本字符串的开头时,您需要将其加倍。
Sub Test()
Dim MyText As String
Dim x As Long
MyText = "Don't stop me now, I'm having such a good time."
For x = 1 To Len(MyText)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If Mid(MyText, x, 1) = "'" Then
' Sheet1.Cells(x, 1) = "'" & Mid(MyText, x)
' Else
' Sheet1.Cells(x, 1) = Mid(MyText, x)
' End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' or you can do it this way
Sheet1.Cells(x, 1) = IIf(Mid(MyText, x, 1) = "'", "'", "") & Mid(MyText, x)
Next x
End Sub