MIdathUK72
New Member
- Joined
- Apr 7, 2022
- Messages
- 1
- Office Version
- 2019
- Platform
- Windows
Hi
I'm trying to use vba to filter different lists on the same spreadsheet - so for example I have a list of departments and the teams within, and the same thing for region and location. I'm using these to create dynamic ranges to populate active x combo boxes - so, select a department then the box for teams only contains relevant teams, and the same for region and location.
Here is my code:
Private Sub ComboBox1_Change()
Sheets("Options").AutoFilterMode = False
Sheets("Options").Range("$G$1:H1").AutoFilter Field:=1, Criteria1:=ComboBox1.Value
Application.DisplayAlerts = True
Sheets("Options").Range("H:H").SpecialCells(xlCellTypeVisible).Copy
Sheets("Working").Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub
Private Sub ComboBox4_Change()
Sheets("Options").AutoFilterMode = False
Sheets("Options").Range("$p$1:q1").AutoFilter Field:=1, Criteria1:=ComboBox4.Value
Application.DisplayAlerts = True
Sheets("Options").Range("H:H").SpecialCells(xlCellTypeVisible).Copy
Sheets("Working").Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub
When I make a change to ComboBox1, it then jumps to the ComboBox4 code......
I'm also really confused about the autofilter, in terms of turning it off and on...
Grateful for any help!
M
I'm trying to use vba to filter different lists on the same spreadsheet - so for example I have a list of departments and the teams within, and the same thing for region and location. I'm using these to create dynamic ranges to populate active x combo boxes - so, select a department then the box for teams only contains relevant teams, and the same for region and location.
Here is my code:
Private Sub ComboBox1_Change()
Sheets("Options").AutoFilterMode = False
Sheets("Options").Range("$G$1:H1").AutoFilter Field:=1, Criteria1:=ComboBox1.Value
Application.DisplayAlerts = True
Sheets("Options").Range("H:H").SpecialCells(xlCellTypeVisible).Copy
Sheets("Working").Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub
Private Sub ComboBox4_Change()
Sheets("Options").AutoFilterMode = False
Sheets("Options").Range("$p$1:q1").AutoFilter Field:=1, Criteria1:=ComboBox4.Value
Application.DisplayAlerts = True
Sheets("Options").Range("H:H").SpecialCells(xlCellTypeVisible).Copy
Sheets("Working").Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End Sub
When I make a change to ComboBox1, it then jumps to the ComboBox4 code......
I'm also really confused about the autofilter, in terms of turning it off and on...
Grateful for any help!
M