+ Reply to Thread
Results 1 to 4 of 4

loop through array

  1. #1
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    loop through array

    loop through array?
    New to vba and need help. Looping through an array. The array is the value from a text box where a user enters numbers and each number is on a new line. How can I get the value of this into an array and print each value? So far I have the below and all I get is one message box with all the data from the form message box.

    Private Sub CommandButton1_Click()
    Dim myArray As Variant
    Dim x As Integer
    Dim val As Variant
    Dim strString As Variant

    If TextBox1.Value = "" Then

    MsgBox "There is no data in text box. Cannot build Macro!"
    Exit Sub
    End If

    val = TextBox1.Value

    myArray = Split(val, "\n")

    For x = LBound(myArray) To UBound(myArray) 'define start and end of array

    MsgBox (myArray(x))

    Next x ' Loop!




    End Sub
    Last edited by nikko50; 02-10-2013 at 01:43 PM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: loop through array

    Try:

    Please Login or Register  to view this content.
    Also, can you use code tags when you post, please?

  3. #3
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: loop through array

    Sorry about that. Ill give it a try.
    Tracy

  4. #4
    Registered User
    Join Date
    09-28-2012
    Location
    boston
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: loop through array

    It worked. Thanks soooo much!
    Tracy

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1