Solved

using variables to adding items to combo box from textbox

Posted on 2014-07-25
4
136 Views
Last Modified: 2014-07-30
excel 2010
vba
userform
control textbox and combobox

What I need:
I need sometimes to add 2 items from a textbox to the  string I'm adding to my combobox item

But  I need 2 variables:
1 =  the first word
2 =  second word


Example: In textbox55 i may have

2X464 2X465



Dim t As String
Dim s As String
Dim ss As String
Dim i As String
Dim tt As String
Dim r As String

s = UserForm2.TextBox55.Text   ' used if i just want the WHOLE string in the textbox

' next trying to pull out the first values and second value from the textbox
'this is not working
r = InStr(1, UserForm2.TextBox55.Text, " ")
ss = InStr(InStr(1, UserForm2.TextBox55.Text, " ") + 1, UserForm2.TextBox55.Text, " ")


i = "CROSSED TO " & r & " BECAUSE " & ss & "" IS DISCONTINUED"
i should look like this in the combobox:
CROSSED TO 2X464 BECAUSE 2X465 IS DISCONTINUED




t = "NUMBER  " & r & "   IS DISCONTINUED - WITH NO ALTERNATE AVAILABLE"
i should look like this in the combobox:
NUMBER 2X464 IS DISCONTINUED - WITH NO ALTERNATE AVAILABLE

UserForm2.ComboBox30.AddItem t
UserForm2.ComboBox30.AddItem i

Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 3
4 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40219961
To get each value from the textbox you can use Split().

Dim strParts() As String

strParts = Split(textbox55.Text, " ")
'strParts(0)  <- will be 2X464
'strParts(1)  <- will be 2X465

' You can tell how many items there are by using UBound(strParts). 0 means there's 1 and 1 means there's, etc.

Open in new window

0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40221753
Edited a typo in line 5.
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 40229650
THANKS
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40229775
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question