我是 VBA 的新手,我整天都在尝试解决这个问题,因此感谢您提供任何帮助和提示。我试图弄清楚我做错了什么。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim intArray(0, 9) As Integer
Dim strTarget As String
Dim blnFound As Boolean
Dim intRowIndex As Integer
Dim intColumnIndex As Integer
Dim intMatchIndex As Integer
For intRowIndex = 0 To 9
intArray(intRowIndex, intColumnIndex) = Cells(1, Chr(65 + intRowIndex))
Next intRowIndex
strTarget = "Q"
blnFound = False
For intRowIndex = 0 To 1
For intColumnIndex = 0 To 9
If strTarget = intArray(intRowIndex, intColumnIndex) Then
blnFound = True
Exit For
End If
Next intColumnIndex
If blnFound Then
Exit For
End If
Next intRowIndex
If blnFound Then
MsgBox "Match was found at index " & intMatchIndex
Else
MsgBox "No Match found"
End If
End Sub
~~~~~~~~~~~~~~~~~~~~~
当我调试时,它停在这一行:
intArray(intRowIndex, intColumnIndex) = Cells(1, Chr(65 + intRowIndex))
给出错误:运行时错误'9':下标超出范围
谢谢!