Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combobox that populates text boxes on userform

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Combobox that populates text boxes on userform

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


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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform text & combobox population help required please Newbie1 Excel Programming 5 February 28th 04 05:19 PM
Dynamic Text boxes in UserForm Kelley[_2_] Excel Programming 2 November 18th 03 05:59 PM
Having data populate text boxes based on Combobox Value Todd Huttenstine[_2_] Excel Programming 1 November 10th 03 01:35 AM
userform text boxes Jo[_4_] Excel Programming 4 September 23rd 03 03:38 AM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"