Solved

using variables to adding items to combo box from textbox

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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