PC Review


Reply
Thread Tools Rate Thread

Combobox that populates text boxes on userform

 
 
joereed11@gmail.com
Guest
Posts: n/a
 
      10th Feb 2008
Hello

Any help is great. I have a userform that uses two comboboxes in order
to pull in data from that associated row. For example, my worksheet
has multiple rows (which change constantly see below).

What i'm looking for; combobox1 selects Audi, combobox2 selects Blue,
I want the associated values 30000 and 4 door each pulled and put into
a txtbox on my userform. Thanks for your help.


example

cell 1 2 3 4
row a Audi Blue 30000 4 door
row b Audi Red 45000 2 door
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      11th Feb 2008
This worked ok for me:

Option Explicit
Private Sub CommandButton1_Click()

Dim myCol1 As Range
Dim myCol2 As Range
Dim Res As Variant
Dim myFormula As String
Dim myStr As String

If Me.ComboBox1.Value = "" Then
Exit Sub
End If

If Me.ComboBox2.Value = "" Then
Exit Sub
End If

With Worksheets("sheet1")
Set myCol1 = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
Set myCol2 = myCol1.Offset(0, 1)

myFormula = "match(1,(" _
& myCol1.Address & "=""" & Me.ComboBox1.Value & """)*(" _
& myCol2.Address & "=""" & Me.ComboBox2.Value & """),False)"

Res = .Evaluate(myFormula)

If IsError(Res) Then
myStr = "no match"
Else
myStr = Format(myCol1(Res).Offset(0, 2).Value, "$#,##0.00") _
& vbLf & myCol1(Res).Offset(0, 3).Value
End If

Me.TextBox1.Value = myStr
End With

End Sub
Private Sub UserForm_Initialize()

With Me.TextBox1
.MultiLine = True
.WordWrap = True
.Value = ""
End With

With Me.ComboBox1
.Style = fmStyleDropDownList
.AddItem "Audi"
.AddItem "Ford"
.AddItem "Chevy"
End With

With Me.ComboBox2
.Style = fmStyleDropDownList
.AddItem "Red"
.AddItem "Green"
.AddItem "Blue"
End With

End Sub


(E-Mail Removed) wrote:
>
> Hello
>
> Any help is great. I have a userform that uses two comboboxes in order
> to pull in data from that associated row. For example, my worksheet
> has multiple rows (which change constantly see below).
>
> What i'm looking for; combobox1 selects Audi, combobox2 selects Blue,
> I want the associated values 30000 and 4 door each pulled and put into
> a txtbox on my userform. Thanks for your help.
>
> example
>
> cell 1 2 3 4
> row a Audi Blue 30000 4 door
> row b Audi Red 45000 2 door


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drag and drop text in userform text / combo boxes Roger on Excel Microsoft Excel Programming 1 22nd Nov 2009 11:34 AM
Combo Box Choice Populates Text Boxes =?Utf-8?B?UGFwZXJiYWNrIFdyaXRlcg==?= Microsoft Access 8 1st Jun 2006 08:06 PM
ComboBox populates text boxes, how to edit text now? =?Utf-8?B?RHJld1RoZUZhdGhlcg==?= Microsoft Access Forms 2 9th Aug 2005 08:37 PM
Using userform, text boxes =?Utf-8?B?TW9tbw==?= Microsoft Excel Programming 4 23rd Feb 2005 03:45 PM
userform text boxes Jo Microsoft Excel Programming 4 23rd Sep 2003 03:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 AM.