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

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,488
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,156
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Just change this:

Code:
For i = 0 To 2
to this:

Code:
For i = LBound(x) To UBound(x)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,314
Office Version
365
Platform
Windows
Try
Code:
For i = 0 To UBound(x)
        MsgBox "your number are  " & "number" & i + 1 & ">>  " & x(i)
    Next i
 

Forum statistics

Threads
1,077,985
Messages
5,337,533
Members
399,154
Latest member
gavlink

Some videos you may like

This Week's Hot Topics

Top