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 Next100: If i = UBound(Arr, 2) + 1 Then MsgBox "查無此值" Else MsgBox MyCz & "在陣列Arr的第" & i & "列" End If erase arrEnd 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 Next100: If i = UBound(Arr, 2) + 1 Then MsgBox "查無此值" Else MsgBox MyCz & "在陣列Arr的第" & i & "列" End If erase arrEnd Sub