Arie Bos
Board Regular
- Joined
- Mar 25, 2016
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
Hello Excel Masters,
I have 1st combobox with ' MaterialType' This reads from a range called 'NomRange1' Each item in NomRange1 has a named sub range 'NomRange2' so the second combobox 'MaterialSelect' reads from these ranges. Some of the items in the subrange have again their own named sub range, which populates the third combobox 'MaterialSelect2'. The code below does this alright, except for these items that do not have a second level sub range. The code halts and gives a 1004 error, which is logical.
Is it possible to build in an error handler so the code will accept if there is no second level sub range?
I have 1st combobox with ' MaterialType' This reads from a range called 'NomRange1' Each item in NomRange1 has a named sub range 'NomRange2' so the second combobox 'MaterialSelect' reads from these ranges. Some of the items in the subrange have again their own named sub range, which populates the third combobox 'MaterialSelect2'. The code below does this alright, except for these items that do not have a second level sub range. The code halts and gives a 1004 error, which is logical.
Is it possible to build in an error handler so the code will accept if there is no second level sub range?
VBA Code:
Private Sub ComboMaterialType_Change()
If ComboMaterialType.Value = "" Then Exit Sub
Dim NomRange1 As String
NomRange1 = ComboMaterialType.Text
ComboMaterialSelect.List = Application.Transpose(Range(NomRange1))
End Sub
Private Sub ComboMaterialSelect_Change()
If ComboMaterialSelect.Value = "" Then Exit Sub
Dim NomRange2 As String
NomRange2 = ComboMaterialSelect.Text
ComboMaterialSelect2.List = Application.Transpose(Range(NomRange2))
End Sub