excel 如何在二维数组中查找某一值 并返回该值所在第几列
2个回答
展开全部
思路:
1、双循环遍历数组;
2、instr函数查找,找到就用goto语句跳出循环到100;
3、100处重新判断是否找到并输出结果。
Sub 查找数据列数()
Dim Arr, MyCz$, i%, j%
MyCz = "C19"
Arr = [{"A1","B2","C3","D4";"A5","B6","C7","D8";"A9","B10","C11","D12";"A13","B14","C15","D16";"A17","B18","C19","D20"}]
For i = LBound(Arr, 2) To UBound(Arr, 2)
For j = LBound(Arr) To UBound(Arr)
If InStr(Arr(j, i), MyCz) > 0 Then
GoTo 100
End If
Next
Next
100:
If i = UBound(Arr, 2) + 1 Then
MsgBox "查无此值"
Else
MsgBox MyCz & "在数组Arr的第" & i & "列"
End If
erase arr
End Sub
1、双循环遍历数组;
2、instr函数查找,找到就用goto语句跳出循环到100;
3、100处重新判断是否找到并输出结果。
Sub 查找数据列数()
Dim Arr, MyCz$, i%, j%
MyCz = "C19"
Arr = [{"A1","B2","C3","D4";"A5","B6","C7","D8";"A9","B10","C11","D12";"A13","B14","C15","D16";"A17","B18","C19","D20"}]
For i = LBound(Arr, 2) To UBound(Arr, 2)
For j = LBound(Arr) To UBound(Arr)
If InStr(Arr(j, i), MyCz) > 0 Then
GoTo 100
End If
Next
Next
100:
If i = UBound(Arr, 2) + 1 Then
MsgBox "查无此值"
Else
MsgBox MyCz & "在数组Arr的第" & i & "列"
End If
erase arr
End Sub
更多追问追答
追问
在Excel中怎么用 我不太懂哦
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询