如何创建超过 160 行 (10836) 的消息框,以根据选择的行在多列中显示文本?

How to create a message box for more than 160 rows (10836), to display text in multiple columns depending on which row is selected?

我正在使用下面的代码创建一个消息框,该消息框在选择单元格 A1、A2、A3 ... 直到 A9 时显示,然后显示引号中的文本以及单元格 V1 中的文本 ( +21) , W1 (+22) and X1 (+23) for when A1 is selected for example, when A2 is selected it will display the string of text in the code below as well as text in the cells V2, W2 and X2等等。我需要对所有 10836 行执行此操作,但似乎 160 个案例是使用此方法的限制。有没有更有效的方法来做到这一点?任何帮助将不胜感激

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Then
Select Case Target.Row
   Case 1, 2, 3, 4, 5, 6, 7, 8, 9
       MsgBox "Changes : " & Cells(Target.Row, Target.Column + 22) & vbNewLine & " ABC Comments: " & Cells(Target.Row, Target.Column + 23) & vbNewLine & "XYZ Comments: " & Cells(Target.Row, Target.Column + 21), vbInformation, "Comments"
   Case Else:
End Select
End If
End Sub

我的想法与 Darren Bartrup-Cook 相同;这里是完整的:

   Private Sub Worksheet_SelectionChange(ByVal Target As Range)

   Dim LastRow As Integer
   LastRow = 10836

   If Target.Count > 1 Then Exit Sub
   If Target.Column = 1 Then

    Select Case Target.Row
       Case 1 To LastRow
           MsgBox "Changes : " & Cells(Target.Row, Target.Column + 22) & vbNewLine & " ABC Comments: " & Cells(Target.Row, Target.Column + 23) & vbNewLine & "XYZ Comments: " & Cells(Target.Row, Target.Column + 21), vbInformation, "Comments"
       Case Else:
    End Select
    End If

    End Sub

您的代码就快完成了。我建议使用 IF 语句而不是 case 语句。

' Event fired when the user changes the selected cells.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    ' Has user selected a single cell in row A, between 1 to A10836?
    If Target.Cells.Count = 1 And Target.Column = 1 And Target.Row <= 10836 Then

        MsgBox "Changes: " & Cells(Target.Row, 23) & vbCrLf & _
                "ABC Comments: " & Cells(Target.Row, 24) & vbCrLf & _
                "XYZ Comments: " & Cells(Target.Row, 22) & vbCrLf
    End If
End Sub