我需要创建一个显示3个不同Excel范围的消息框。
这是我的数据:
我需要有一个如下所示的消息框:
单击“确定”后,应显示如下的B1:B6:
然后,当您再次单击“确定”时,它将显示范围C1:C6。
到目前为止,这是我的代码:
Sub Message_Box()
Dim a As Range
Dim sTxt As String
For Each a In ThisWorkbook.Sheets("Sheet1").Range("a1:a6")
sTxt = sTxt & vbLf & a.Value
Next a
MsgBox sTxt
End Sub
最佳答案
Sub Message_Box()
Dim a As Range
Dim t As Integer
Dim sTxt As String
For t = 1 To 3
For Each a In ThisWorkbook.Sheets("Sheet1").Range(Cells(1, t), Cells(6, t))
sTxt = sTxt & vbLf & a.Value
Next a
MsgBox sTxt
sTxt = ""
Next t
End Sub