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

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Just change this:

Code:
For i = 0 To 2

to this:

Code:
For i = LBound(x) To UBound(x)
 
Upvote 0
Try
Code:
For i = 0 To UBound(x)
        MsgBox "your number are  " & "number" & i + 1 & ">>  " & x(i)
    Next i
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,947
Members
452,539
Latest member
delvey

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top