Solved

using variables to adding items to combo box from textbox

Posted on 2014-07-25
4
140 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 48

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 48

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 48

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

617 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