ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Row Source based on a filtered list (https://www.excelbanter.com/excel-programming/379096-row-source-based-filtered-list.html)

easy

Row Source based on a filtered list
 
Hi first post here.
I have a problem creating a row source for a combo box.
I have a worksheet that has 3 columns:
"Code", "Type", "Description"

On my form there are 2 combo boxes.
Combo box selects the "Type"
What I want the second combo box to do is create its list from the records
on the worksheet where the rcords are of the "type" selected by the first box.
(Same as AuotFilter works)
Any help greatly appreciated, but take it easy i'm a newbie to vba

TIA

Tom Ogilvy

Row Source based on a filtered list
 
Just loop through the range and where the entry in the second column equals
the selected type, use additem to add the data to the second combobox.

--
Regards,
Tom Ogilvy

"easy" wrote in message
...
Hi first post here.
I have a problem creating a row source for a combo box.
I have a worksheet that has 3 columns:
"Code", "Type", "Description"

On my form there are 2 combo boxes.
Combo box selects the "Type"
What I want the second combo box to do is create its list from the records
on the worksheet where the rcords are of the "type" selected by the first
box.
(Same as AuotFilter works)
Any help greatly appreciated, but take it easy i'm a newbie to vba

TIA




easy

Row Source based on a filtered list
 
Thanks for the reply Tom, at least I know it can be done!
But as a newbie I got lost after
"just loop through..."
Any chance of giving an example of code? or where to look for examples

"Tom Ogilvy" wrote:

Just loop through the range and where the entry in the second column equals
the selected type, use additem to add the data to the second combobox.

--
Regards,
Tom Ogilvy

"easy" wrote in message
...
Hi first post here.
I have a problem creating a row source for a combo box.
I have a worksheet that has 3 columns:
"Code", "Type", "Description"

On my form there are 2 combo boxes.
Combo box selects the "Type"
What I want the second combo box to do is create its list from the records
on the worksheet where the rcords are of the "type" selected by the first
box.
(Same as AuotFilter works)
Any help greatly appreciated, but take it easy i'm a newbie to vba

TIA





Dave Peterson

Row Source based on a filtered list
 
I put a couple of comboboxes on a userform and used this:

Option Explicit
Dim BlkProc As Boolean
Private Sub ComboBox1_Change()

Dim myCell As Range
Dim myRng As Range
With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

BlkProc = True
Me.ComboBox2.Clear

If Me.ComboBox1.Value < 0 Then
'do nothing
Else
For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase(Me.ComboBox1.Value) Then
Me.ComboBox2.AddItem myCell.Offset(0, 1).Value
End If
Next myCell
End If
BlkProc = False

End Sub

Private Sub ComboBox2_Change()
If BlkProc = True Then Exit Sub
'any other code you want here
End Sub

Private Sub UserForm_Initialize()
With Me.ComboBox1
.Style = fmStyleDropDownList
.AddItem "A"
.AddItem "B"
.AddItem "C"
End With
End Sub



easy wrote:

Thanks for the reply Tom, at least I know it can be done!
But as a newbie I got lost after
"just loop through..."
Any chance of giving an example of code? or where to look for examples

"Tom Ogilvy" wrote:

Just loop through the range and where the entry in the second column equals
the selected type, use additem to add the data to the second combobox.

--
Regards,
Tom Ogilvy

"easy" wrote in message
...
Hi first post here.
I have a problem creating a row source for a combo box.
I have a worksheet that has 3 columns:
"Code", "Type", "Description"

On my form there are 2 combo boxes.
Combo box selects the "Type"
What I want the second combo box to do is create its list from the records
on the worksheet where the rcords are of the "type" selected by the first
box.
(Same as AuotFilter works)
Any help greatly appreciated, but take it easy i'm a newbie to vba

TIA





--

Dave Peterson


All times are GMT +1. The time now is 02:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com