Question

I have TheMax and TheMin sub procedures to show the max/min values from the same column. How do I show both values in the same MsgBox? Original scripts:

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

As you can see, now each value shows in a separate MsgBox. I would like to show both in one MsgBox. Thank you.

Was it helpful?

Solution

Simply combine your two functions and concatenate the values returned.

Code:

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

Result:

enter image description here

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top