如何将MsgBox中的两个值放在一列中?

时间:2014-03-26 22:04:07

标签: vba msgbox

我有TheMax和TheMin子程序来显示同一列的最大/最小值。如何在同一个MsgBox中显示这两个值?原始脚本:

Sub ShowMax()
   Dim TheMax As Double
   TheMax = WorksheetFunction.Max (Range("A:A"))
   MsgBox TheMax
End Sub

Sub ShowMin()
   Dim TheMin As Double
   TheMin = WorksheetFunction.Min (Range("A:A"))
   MsgBox TheMin
End Sub

如您所见,现在每个值都显示在单独的MsgBox中。我想在一个MsgBox中显示两者。谢谢。

2 个答案:

答案 0 :(得分:2)

只需组合两个函数并连接返回的值。

代码:

Sub ShowMinMax()
   Dim TheMin As Double, TheMax As Double
   TheMin = WorksheetFunction.Min(Range("A:A"))
   TheMax = WorksheetFunction.Max(Range("A:A"))
   MsgBox "Min: " & TheMin & " Max: " & TheMax
End Sub

<强>结果:

enter image description here

答案 1 :(得分:1)

Function ShowMax()
   Dim TheMax As Double
   ShowMax = WorksheetFunction.Max (Range("A:A"))
End Function

Function ShowMin()
   Dim TheMin As Double
   ShowMin = WorksheetFunction.Min (Range("A:A"))
End Function

Sub CallMsgBox()
   msgbox ShowMax() & " " & ShowMin
End Sub