Results 1 to 4 of 4

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

  1. #1
    Board Regular
    Join Date
    Mar 2016
    Posts
    1,439
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

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

    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

  2. #2
    Board Regular steve the fish's Avatar
    Join Date
    Oct 2009
    Location
    Midlands, UK
    Posts
    7,671
    Post Thanks / Like
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)

    Default Re: asking user to enter numbers and msg out these numbers -vba

    Change the for line to:

    Code:
    For i = 0 To UBound(x)
    Looking for opportunities

  3. #3
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,993
    Post Thanks / Like
    Mentioned
    53 Post(s)
    Tagged
    6 Thread(s)

    Default Re: asking user to enter numbers and msg out these numbers -vba

    Just change this:

    Code:
    For i = 0 To 2
    to this:

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

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,229
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    49 Thread(s)

    Default Re: asking user to enter numbers and msg out these numbers -vba

    Try
    Code:
    For i = 0 To UBound(x)
            MsgBox "your number are  " & "number" & i + 1 & ">>  " & x(i)
        Next i
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •