Consulting

Results 1 to 7 of 7

Thread: Solved: Pass Multiple Values from A Textbox

  1. #1
    VBAX Tutor jo15765's Avatar
    Joined
    Oct 2011
    Posts
    281
    Location

    Solved: Pass Multiple Values from A Textbox

    I have a Excel UserForm that has a textbox on it. Pretty straightforward and simple. The code behind the textbox is:
    [vba]
    Dim BookNames
    Dim BookName
    Dim wb As Excel.Workbook
    Dim q

    BookNames = Array(UserForm_One.TextBox1.Text)

    For Each BookName In BookNames
    Call Daily_Report(BookName)
    Call Cumulative_Manual(BookName)
    Next BookName
    [/VBA]

    My question is, is it possible for me to enter more than one Book Name into that textbox and have it enter the Array at a time (w/o doing mass changes to coding)?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Dim Booknames() as String and use Split() and set the delimiter to vblf or whatever you delimit the textbox value by.

  3. #3
    VBAX Tutor jo15765's Avatar
    Joined
    Oct 2011
    Posts
    281
    Location
    How would I use Split()? I have never used this before...

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    To find help in VBE, press F1 with cursor in or near the keyword. Or just use F2 to browse to the command.

    [VBA]Private Sub CommandButton1_Click()
    Dim BookNames() As String
    Dim BookName As Variant
    Dim wb As Excel.Workbook
    Dim q

    BookNames() = Split(UserForm_One.TextBox1.Text, vbLf)
    MsgBox Join(BookNames(), vbLf)

    For Each BookName In BookNames()
    Call Daily_Report(BookName)
    Call Cumulative_Manual(BookName)
    Next BookName
    End Sub[/VBA]

  5. #5
    VBAX Tutor jo15765's Avatar
    Joined
    Oct 2011
    Posts
    281
    Location
    I pressed F1 on the vbLF looking to see if it would show me other options that I could use such as a comma or a semi-colon, but it didn't Is it possible to use a comma as my separator?

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    vblf is a constant. Join() is the command that contains the delimiter parameter.

  7. #7
    VBAX Tutor jo15765's Avatar
    Joined
    Oct 2011
    Posts
    281
    Location
    Ah okay, the catch I kept hitting was I needed to add the delimiter to both the JOIN and the SPLIT functions. Thanks for the examples as well as the guidance!

Posting Permissions

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