asking user to enter numbers and msg out these numbers -vba

lezawang

Well-known Member
Hi
With a help from Fluff, I created the code below. It is asking user to enter 3 numbers then the code will msg out these 3 numbers. I want to improve this code. I do not want to limit user to enter only 3 numbers. I want a user to enter any number and I will create a loop depend on how many numbers user entered. Any help would be appreciated. Thank you.
Code:
' asking users to enter multiple numbers and then msgboxing them 1 by 1
Sub myarray()
    Dim x As Variant
    Dim i As Integer
    x = InputBox("enter 3 numbers like 1,2,3")
    x = Split(x, ",")
    For i = 0 To 2
        MsgBox "your number are  " & "number" & i + 1 & ">>  " & x(i)
    Next i
End Sub
 

Fluff

MrExcel MVP, Moderator
Try
Code:
For i = 0 To UBound(x)
        MsgBox "your number are  " & "number" & i + 1 & ">>  " & x(i)
    Next i
 

Some videos you may like

This Week's Hot Topics

Top