我正在尝试创建一个消息框,以显示未确定列数的各种条目。
我相信我想要一个循环,但是我希望消息框显示该范围内所有可用的记录,而不是为该范围内的每个项目创建一个新的消息框。
我希望消息框看起来像
Loan Summary(Price, Range, Standard Deviation):
Loan 1: (100, 5, 2)
Loan 2: (102, 4, 3)
,依此类推,但记录(贷款)的数量每次都会改变。
我有以下代码。如何为范围内的每条记录添加新行?
For theRep = 1 To wsv.Range("J3").Value
Average1 = Range("loanSummary").Offset(0, theRep)
Range1 = Range("loanSummary").Offset(1, theRep)
StdDev1 = Range("loanSummary").Offset(2, theRep)
MsgBox "Loan Summary (Price, Range, Standard Deviation):" & vbCrLf & vbTab & "Loan 1: " & Format(Average1, "##0.00") & ", " & Format(Range1, "##0.00") & ", " & Format(StdDev1, "##0.00")
Next
答案 0 :(得分:0)
使用字符串变量保存数据,然后在循环后将字符串显示在一个MsgBox中
Dim str As String
str = "Loan Summary (Price, Range, Standard Deviation):" & vbCrLf & vbTab
For theRep = 1 To wsv.Range("J3").Value
Average1 = Range("loanSummary").Offset(0, theRep)
Range1 = Range("loanSummary").Offset(1, theRep)
StdDev1 = Range("loanSummary").Offset(2, theRep)
str = str & "Loan " & theRep & ": (" & Format(Average1, "##0.00") & ", " & Format(Range1, "##0.00") & ", " & Format(StdDev1, "##0.00") & ")" & vbCrLf & vbTab
Next
MsgBox str