-
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)?
-
Dim Booknames() as String and use Split() and set the delimiter to vblf or whatever you delimit the textbox value by.
-
How would I use Split()? I have never used this before...
-
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]
-
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?
-
vblf is a constant. Join() is the command that contains the delimiter parameter.
-
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
-
Forum Rules