2 ComboBox

haseft

Active Member
Joined
Jun 10, 2014
Messages
321
hi,
I have a userform with 2 listbox,
ListBox1, pupulate uniqe items from column B in Sheet1, workning well,

Need help with ComboBox2.
want to fill ComboBox2 with criteria choosen fron ComboBox1
ComboBox2 should show item from column A in Sheet1
Tanks,

VBA Code:
Private Sub UserForm_Initialize()
Dim myCollection As Collection, cell As Range

On Error Resume Next
Set myCollection = New Collection
With ComboBox1
  .Clear
For Each cell In Sheets("Sheet1").Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
If Len(cell) <> 0 Then
  Err.Clear
  myCollection.Add cell.Value, cell.Value
  If Err.Number = 0 Then .AddItem cell.Value
End If
Next cell
End With
ComboBox1.ListIndex = 0

End Sub

Private Sub ComboBox1_Change()
'want to fill ComboBox2 with criteria choosen from ComboBox1
'ComboBox2 should show items from column A in Sheet1

With ComboBox2
.ColumnCount = 1
.ColumnWidths = "50"
.ColumnHeads = True
[B]'how ?[/B]


End With
End Sub
 
this is the Sheet1
textboxes data from column E, H and J in Sheet1 .

'TextBox1.value = data from clomn E
TextBox2.value = data from clomn H
TextBox3.value = data from clomn J

YearOrgOrgnrGroupNummberDesitionAmountCopyDatum1Datum2
2 016aaa1STY022017-01-012019-12-30
2017aaa11 200 tkrSTY900 00012017-01-012019-12-31
2018aaa1STY900 00012017-01-012019-12-31
2019aaa1STY900 00012017-01-012019-12-31
2018sss3500 tkrSTY100 00012018-06-152018-08-31
2015bbb3SPG25 0002
2 016bbb3SPG19 00012016-01-012016-12-31
2017bbb325 tkrSPG12 50022017-01-012018-12-31
2018bbb3SPG12 50022017-01-012018-12-31
2020www325 tkrSPG10 0002202-01-01 2020-12-31
2015rrr2STY12 0002
2 016rrr2STY50 00012016-01-012016-12-31
2017rrr252 tkrSTY52 00012017-01-012017-12-31
2018rrr254,6 tkrSTY55 00012018-01-012020-12-31
2019rrr2STY55 00012018-01-012020-12-31
2020rrr2STY55 00012018-01-012020-12-31
2019yyy235 tkrSPG02
2019ooo410 tkrSPG5 00022019-01-012019-12-31
2018qqq450 tkrTommy10 00022018-08-012018-12-31
2019qqq4SPG022019-01-012019-12-31
2015ppp3SPG20 0001
2 016ppp3SPG10 00022016-10-012017-09-30
2017ppp360 tkrSPG10 00022017-07-012019-06-30
2018ppp3SPG10 00022017-07-012019-06-30
2019ppp310 tkrSPG10 00022019-01-012019-12-31
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This is Sheet1
 

Attachments

  • Sheet1.JPG
    Sheet1.JPG
    99.9 KB · Views: 5
Upvote 0
As col A has numbers, use this
VBA Code:
   With UfDic(Me.ComboBox1.Value)
      Me.TextBox1 = .Item(Val(Me.ComboBox2.Value))(0)
      Me.TextBox2 = .Item(Val(Me.ComboBox2.Value))(1)
      Me.TextBox3 = .Item(Val(Me.ComboBox2.Value))(2)
   End With
 
Upvote 0
Solution
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,209
Members
448,874
Latest member
b1step2far

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top