我有使用 Application.Match 在数组中查找位置的代码。但是我该如何反其道而行之:根据位置在数组中查找值?
问问题
171 次
1 回答
0
it is a 1D array "posArr () As Variant". so if the array contains "milk, coke, water" and i want to find the value in position 3 ill "Ar(3) = posArr"? – GodAtum 8 mins ago
Further to my example, see these two examples.
Finding out what is at position 3
Sub Sample()
Dim posArr
Dim s As String
Dim pos As Long
pos = 3 '~~> 3rd Position
s = "milk,coke,water"
posArr = Split(s, ",")
Debug.Print posArr(pos - 1)
End Sub
Checking if the value at position 3 is "water"
Sub Sample()
Dim posArr
Dim s As String
Dim pos As Long
pos = 3 '~~> 3rd Position
s = "milk,coke,water"
posArr = Split(s, ",")
If posArr(pos - 1) = "water" Then MsgBox "What an awesome guess!"
End Sub
The reason why we do - 1
because the lowest bound is 0
于 2013-11-14T10:16:23.853 回答