Solved

using variables to adding items to combo box from textbox

Posted on 2014-07-25
4
139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 47

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 47

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 47

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

752 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