excel - 循环显示多条记录的消息框
问题描述
我正在尝试创建一个消息框,显示未确定数量的列的各种条目。
我相信我想要一个循环,但我希望消息框显示一个范围内的所有可用记录,而不是为范围内的每个项目创建一个新的消息框。
我希望消息框看起来像
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
解决方案
使用字符串变量来保存数据,然后在循环之后将字符串显示在一个 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
推荐阅读
- android-source - Stop SE Linux from Enforcing on Android AOSP
- java - How to take the values from the variable and enter in the text box?
- java - how to index each feature elasticsearch featurecollection
- python - 通过对具有数字和字符串变量的数据框进行分组来转置
- excel - VBA Excel String concatenation upper than max length, How to?
- c++ - 依赖于未知 typedef 的模板特化
- sorting - Sorting arraylist of objects based on String property
- php - 如何在 fpdi 中添加页眉(徽标)和页脚(带有页码的徽标)
- reactjs - 如何从 React JS 中的重复元素中获取价值
- git - 禁止 heroku 在每次推送到 github 拉取请求时重新部署审查应用程序