Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- Windows
I'm having some trouble getting the dynamic properties of a named range to transfer to a ComboBox on a user form. I have a macro using an advanced filter that populates the sorted results based on the OptionButton selected on the form. Not having any trouble here, everything filters and sorts as it should. I'm using the following formula inside a named range to keep the results of the advanced filter dynamic and exclude any blank rows:
Haven't had any issues using this formula in the past for dynamic drop down lists with on sheet Data Validation but with this user form ComboBox the results are less than stellar. My OptionButtons are All, Active & Inactive. The ComboBox should display the list of project names based on those OptionButtons. I get varying results in the ComboBox depending on the order the OptionButtons are selected. For example, if there are 20 names total under All and only 10 are Active and 10 Inactive, when I select All first, I see all 20 and then select Active or Inactive, I'll get 10 results with 10 blank rows. Vice versa, select Active first then select All, I only see 10 results of the full 20, no empty rows.
I have the RowSource for the ComboBox set to the dynamic Named Range.
Each OptionButton runs the macro (see below) that runs the advanced filter and sort on the Client_Db worksheet.
What am I missing? Why is the ComboBox displaying empty rows when it shouldn't and incomplete results when the resulting list is longer than the previous list selection?
Rich (BB code):
OFFSET('12-13_Client_Db'!$AQ$1,1,,COUNTA('12-13_Client_Db'!$AQ$1:$AQ$99999)-1,1)
Haven't had any issues using this formula in the past for dynamic drop down lists with on sheet Data Validation but with this user form ComboBox the results are less than stellar. My OptionButtons are All, Active & Inactive. The ComboBox should display the list of project names based on those OptionButtons. I get varying results in the ComboBox depending on the order the OptionButtons are selected. For example, if there are 20 names total under All and only 10 are Active and 10 Inactive, when I select All first, I see all 20 and then select Active or Inactive, I'll get 10 results with 10 blank rows. Vice versa, select Active first then select All, I only see 10 results of the full 20, no empty rows.
I have the RowSource for the ComboBox set to the dynamic Named Range.
Each OptionButton runs the macro (see below) that runs the advanced filter and sort on the Client_Db worksheet.
What am I missing? Why is the ComboBox displaying empty rows when it shouldn't and incomplete results when the resulting list is longer than the previous list selection?
VBA Code:
Sub sortPROJECTS()
With clientDB
lastROW = .Range("A99999").End(xlUp).Row 'last row
If lastROW < 2 Then Exit Sub 'no results, exit out
'''sort by project type
If AddClientForm.activeOPT.Value = True Then
.Range("AC2").Value = "Active"
ElseIf AddClientForm.inactiveOPT.Value = True Then
.Range("AC2").Value = "Inactive"
ElseIf AddClientForm.viewallOPT.Value = True Then
.Range("AC2").Value = "<>"
End If
'''run advanced filter
.Range("A1:Y" & lastROW).AdvancedFilter xlFilterCopy, .Range("AB1:AM2"), .Range("AQ1:BC1"), True
lastRESROW = .Range("BC99999").End(xlUp).Row 'last result row
If lastRESROW < 2 Then Exit Sub
If lastRESROW < 3 Then GoTo SkipSort
With .Sort
.SortFields.Clear
.SortFields.Add clientDB.Range("AQ2"), xlSortOnValues, xlAscending, DataOption:=xlSortNormal 'sort
.SetRange clientDB.Range("AQ2:BC" & lastRESROW) 'set sort range
.Apply
End With
.Calculate
SkipSort:
End With
End Sub
VBA Code:
Private Sub activeOPT_Click()
sortPROJECTS
End Sub
Private Sub inactiveOPT_Click()
sortPROJECTS
End Sub
Private Sub viewallOPT_Click()
sortPROJECTS
End Sub