ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   2 comboboxes working 2gether (https://www.excelbanter.com/excel-programming/309772-re-2-comboboxes-working-2gether.html)

nrage21[_60_]

2 comboboxes working 2gether
 
Teams...............BX#1.....BX#2...etc....etc.... .etc
BX#1...................AA.......AW
BX#2...................CB.......CR
BX#3...................GB.......ET
BX Sites...............HC.......JV
BX 149.................JH.......MP
MH#1...................LJ.......NG
MH#2...................LR......TS
MH Sites...............MP.....TP

I need help making 2 comboboxes work together in an "userform". I don't
even know how to start with the VBA code. I can populate the 1st
combobox with the team list... but I need that when the user selects a
team, that the corresponding information is populated in the 2nd
combobox.

For example, if the user selects "BX#1", then the BX#1 list is
populated in the 2nd combobox. If user selects "MH Sites" then the MH
Sites list is populated and so on.

There are 24 different list depending on 1st selection.

Please experts, help me!

- Larry -
VBA Amateur


---
Message posted from http://www.ExcelForum.com/


nrage21[_61_]

2 comboboxes working 2gether
 
Can anyone help?

- Larry -
VBA Amateu

--
Message posted from http://www.ExcelForum.com


nrage21[_62_]

2 comboboxes working 2gether
 
Help

- Larry -
VBA Amateu

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

2 comboboxes working 2gether
 
How about something like:

Option Explicit
Dim blkProc As Boolean
Private Sub ComboBox1_Change()

Dim FoundCell As Range
Dim myRng As Range

blkProc = True
Me.ComboBox2.Clear
blkProc = False

If Me.ComboBox1.ListIndex = -1 Then
Exit Sub
Else
With Worksheets("sheet1")
With .Rows(1)
Set FoundCell = .Cells.Find(what:=Me.ComboBox1.Value, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, lookat:=xlWhole, _
MatchCase:=False)
If FoundCell Is Nothing Then
MsgBox "Design error!" & vbLf & "please call Larry @xxxx"
Exit Sub
End If
End With

Set myRng = .Range(.Cells(2, FoundCell.Column), _
.Cells(.Rows.Count, FoundCell.Column).End(xlUp))
Me.ComboBox2.List = myRng.Value

End With
End If

End Sub

Private Sub ComboBox2_Change()
If blkProc Then Exit Sub
MsgBox "hi"
End Sub

Private Sub UserForm_Initialize()

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

Me.ComboBox1.List = myRng.Value

End Sub


"nrage21 <" wrote:

Help

- Larry -
VBA Amateur

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson



All times are GMT +1. The time now is 02:55 AM.

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