Hello everyone.
Mr.Excel is an amazing resource, I'm trying to leverage everyone's expertise once again.
I have a userform with comboboxes the populates the last row of table. When the user selects a certain "AREA" in cmbAREA combobox, i want to show a list of "UNIT" related to that "AREA" in cmbUnit combobox. Below is the code I have put together. My issue is when the user selects an "AREA", no list is populating the "UNIT" combobox. Similarly for the next relationship down with "TYPE1" and TYPE2. Not sure what I am doing wrong. Help would be much appreciated.
Mr.Excel is an amazing resource, I'm trying to leverage everyone's expertise once again.
I have a userform with comboboxes the populates the last row of table. When the user selects a certain "AREA" in cmbAREA combobox, i want to show a list of "UNIT" related to that "AREA" in cmbUnit combobox. Below is the code I have put together. My issue is when the user selects an "AREA", no list is populating the "UNIT" combobox. Similarly for the next relationship down with "TYPE1" and TYPE2. Not sure what I am doing wrong. Help would be much appreciated.
Code:
Private Sub UserForm_Initialize()
'Variable declaration
Dim idVal As Integer
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Register")
'Defining the last row in the Data Sheet ad IdVal
idVal = ws.Cells(Rows.Count, "A").End(xlUp).Row + 1
'Update next available id on the userform
frmData.txtSEQUENCENUMBER = idVal - 99
'Enters ranges for comboboxes
With ThisWorkbook.Sheets("Lookup")
cmbREV.List = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
cmbAREA.List = .Range("B2:D" & .Range("B" & .Rows.Count).End(xlUp).Row).Value
Application.EnableEvents = False
cmbUNIT.Clear
Application.EnableEvents = True
Select Case cmbAREA.Text
Case "BLD"
cmbUNIT.List = .Range("D2:D" & .Range("D" & .Rows.Count).End(xlUp).Row).Value
Case "CO2"
cmbUNIT.List = .Range("E2:E" & .Range("E" & .Rows.Count).End(xlUp).Row).Value
Case "DOM"
cmbUNIT.List = .Range("F2:F" & .Range("F" & .Rows.Count).End(xlUp).Row).Value
Case "FLR"
cmbUNIT.List = .Range("G2:G" & .Range("G" & .Rows.Count).End(xlUp).Row).Value
Case "INL"
cmbUNIT.List = .Range("H2:H" & .Range("H" & .Rows.Count).End(xlUp).Row).Value
Case "LNG"
cmbUNIT.List = .Range("I2:I" & .Range("I" & .Rows.Count).End(xlUp).Row).Value
Case "SAF"
cmbUNIT.List = .Range("J2:J" & .Range("J" & .Rows.Count).End(xlUp).Row).Value
Case "SRV"
cmbUNIT.List = .Range("K2:K" & .Range("K" & .Rows.Count).End(xlUp).Row).Value
Case "STL"
cmbUNIT.List = .Range("L2:L" & .Range("L" & .Rows.Count).End(xlUp).Row).Value
Case "UTL"
cmbUNIT.List = .Range("M2:M" & .Range("M" & .Rows.Count).End(xlUp).Row).Value
End Select
cmbTYPE1.List = .Range("N2:N" & .Range("N" & .Rows.Count).End(xlUp).Row).Value
Application.EnableEvents = False
cmbTYPE2.Clear
Application.EnableEvents = True
Select Case cmbTYPE1.Text
Case "INSPECTION"
cmbTYPE2.List = .Range("O2:O" & .Range("O" & .Rows.Count).End(xlUp).Row).Value
Case "NDT"
cmbTYPE2.List = .Range("P2:P" & .Range("P" & .Rows.Count).End(xlUp).Row).Value
Case "SCOPE"
cmbTYPE2.List = .Range("Q2:Q" & .Range("Q" & .Rows.Count).End(xlUp).Row).Value
Case "VENDOR"
cmbTYPE2.List = .Range("R2:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
Case "COMPLIANCE"
cmbTYPE2.List = .Range("S2:S" & .Range("S" & .Rows.Count).End(xlUp).Row).Value
End Select
cmbPERSON1.List = .Range("T2:T" & .Range("T" & .Rows.Count).End(xlUp).Row).Value
cmbPERSON2.List = .Range("T2:T" & .Range("T" & .Rows.Count).End(xlUp).Row).Value
txtEQUIPMENT.Text = "GGP-"
End With
End Sub