数组中有张三、李四两个字符串,用vba生成一个判断,
时间: 2023-04-09 08:04:49 浏览: 133
判断一行字符串中的数字出现的个数
判断如果数组中包含"张三"则输出"张三在数组中",如果包含"李四"则输出"李四在数组中",如果都不包含则输出"数组中没有张三或李四"。
以下是 VBA 代码:
Sub CheckArray()
Dim arr(1 To 2) As String
Dim i As Integer
Dim found As Boolean
arr(1) = "张三"
arr(2) = "李四"
For i = 1 To 2
If arr(i) = "张三" Then
found = True
Debug.Print "张三在数组中"
ElseIf arr(i) = "李四" Then
found = True
Debug.Print "李四在数组中"
End If
Next i
If Not found Then
Debug.Print "数组中没有张三或李四"
End If
End Sub
阅读全文