MsgBox question

How to display values of 2 variables which range from 4 to 15 in 1 message window using MsgBox?

Almir's picture

You can generate random number pairs from the range

If variables are random, I would simply use:

MsgBox WorksheetFunction.RandBetween(4, 15) & " and " & WorksheetFunction.RandBetween(4, 15)

However, there is a drawback: there could be two same numbers together. If you don'want it, use this function and call it in message box (thanks to J.E. McGimpsey ):

Check it here: http://excelexperts.com/solution-how-display-values-2-variables-which-ra...

Thanks for the advice, but I

Thanks for the advice, but I need to set 2 variables as Integer and set their values from 4 to 15 first, then use MgBox to show their values. I know it must be basic stuff, but I never studied VBA.

Almir's picture

Could you post desired output here?

Is this what you need?

Sub Test()

Dim V1 As Integer
Dim V2 As Integer

V1 = 4
V2 = 15

MsgBox V1 & " " & V2

End Sub