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

lezawang

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

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,692
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
36,059
Office Version
365
Platform
Windows
Try
Code:
For i = 0 To UBound(x)
        MsgBox "your number are  " & "number" & i + 1 & ">>  " & x(i)
    Next i
 

Watch MrExcel Video

Forum statistics

Threads
1,090,323
Messages
5,413,801
Members
403,503
Latest member
Wezoin

This Week's Hot Topics

Top