我写了一个宏来从列表中获取单个值。我的意图是跳过那些用引号引起来的值。我该怎么办?
到目前为止,我已经写过:
Sub dosth()
Dim post As Variant
For Each post In [{"1","'2'","3","'4'"}]
Debug.Print post
Next post
End Sub
产生的结果:
1
'2'
3
'4'
我希望拥有的东西
1
3
在这里找不到要应用任何条件逻辑的想法。我该如何实现?
答案 0 :(得分:1)
使用ascii值进行测试。 39是'
。
Option Explicit
Sub dosth()
Dim elements As Variant, post As Variant
elements = [{"1","'2'","3","'4'"}]
For Each post In elements
If AscW(post) <> 39 Then Debug.Print post
Next post
End Sub
类似的想法
Option Explicit
Sub dosth()
Dim elements As Variant, post As Variant
elements = [{"1","'2'","3","'4'"}]
For Each post In elements
If Not Left$(post, 1) = Chr$(39) Then Debug.Print post
Next post
End Sub