Solved

using variables to adding items to combo box from textbox

Posted on 2014-07-25
4
132 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 45

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 45

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 45

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now