VBA中数组元素的内容

时间:2016-06-16 10:47:21

标签: arrays string vba

我想知道如何检查VBA中数组的第n个元素是否包含某些字符 - 例如总内容为"我的电子邮件地址是a.asdf@xyz.com"所以数组元素将是"我的","电子邮件","地址"其中一个将是" a.asdf@xyz.com" 我需要知道哪个元素以" a。"开头。然后打印该数组的元素。

1 个答案:

答案 0 :(得分:1)

这应该向您展示基本想法

Sub ArrayCheck()
    Dim myArray(1 To 5) As String
    myArray(1) = "My"
    myArray(2) = "email"
    myArray(3) = "address"
    myArray(4) = "a.asdf@xyz.com"
    myArray(5) = "some other stuff"

    Dim strElement As Variant
    For Each strElement In myArray
        If strElement Like "a.*" Then
            MsgBox "Hit: " & strElement
        End If
    Next strElement
End Sub