PDA

View Full Version : Solved: UserForm;ComboBox;FilterData



sengsara
03-04-2009, 01:28 AM
Please
Please
Please ,,,

Help me with this comboBox

Thanks

Bob Phillips
03-04-2009, 01:38 AM
Private Sub ComboBox1_Change()
Me.ComboBox2.ListIndex = Me.ComboBox1.ListIndex
End Sub

Private Sub Userform_Activate()
Dim LastRow As Long

With Worksheets("Sheet1")

LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Me.ComboBox1.List = Application.Transpose(.Range("B2").Resize(LastRow - 1))
Me.ComboBox2.ColumnCount = 2
Me.ComboBox2.List = Application.Transpose(Application.Transpose(.Range("C2").Resize(LastRow - 1, 2)))
End With
End Sub


but I would use a textbox not a secondary combobox.

sengsara
03-04-2009, 04:09 AM
thanks Xld for reply
am waiting for long time

i put your code into the userform
then combox1 show so much duplicate M 031
and combox2 show all data

can macro make combobox1 only show M 031;M 032;M 033 and not show duplicate M 031
then combobox2 only show the data from M 031 not all data

if use a textbox as secondary can user choose that data and transfer into database with commandbutton?

thanks

Bob Phillips
03-04-2009, 05:35 AM
You want dependent dropdowns don't you? In that case I would make the second combo a listbox.

Bob Phillips
03-04-2009, 08:50 AM
Here is some cde based on a Listbox



Private Sub ComboBox1_Change()
Dim LastRow As Long
Dim NextRow As Long

With Worksheets("Sheet1")

LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Me.ListBox1.Clear

For i = 2 To LastRow

If .Cells(i, "B").Value = Me.ComboBox1.Value Then

NextRow = NextRow + 1

Me.ListBox1.AddItem .Cells(i, "C").Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = .Cells(i, "D").Value
End If
Next i
End With
End Sub

Private Sub Userform_Activate()
Dim LastRow As Long
Dim coll As Collection
Dim itm As Variant

With Worksheets("Sheet1")

LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

Set coll = New Collection
On Error Resume Next
For i = 2 To LastRow

coll.Add .Cells(i, "B").Value, .Cells(i, "B").Value
Next i
On Error GoTo 0

For Each itm In coll

Me.ComboBox1.AddItem itm
Next itm

Me.ListBox1.ColumnCount = 2
End With
End Sub

sengsara
03-05-2009, 03:57 AM
Wowww...perfect
thanks Xld you're cool....
you know what am looking for
thanks for your help...
GBU