mrstaggart
MIS
I am making a form for the sales team.
I have a drop down to select a product. With a macro attached to a button, the macro filters an item list based on the selected product. (Similar to this thread as a start point: The form is locked, but the drop down cell for selection is not (obviously).
When selecting a value like "Fruit" or "Dairy", it works great. When trying to select blank it fails -- MS VB "Run time error '1004': ShowAllData method of Worksheet class failed". With the form locked, I also noticed in the Data ribbon - Sort & Filter group - "Clear" option is gray.
The macro text follows, where C9 is my select-box-result-cell for product (<blank>,Fruit, Dairy) and my filtered data is in cell range A13 to H250:
Sub Product_List()
'
' Product_List Macro
' If Pricing for Product is blank, it unfilters all; if not blank, filters for matches in Col B
'
If Range("C9") = 0 Then
ActiveSheet.ShowAllData
Range("A1").Select
Else
Range("A13:H250").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("C8:C9"), Unique:=False
End If
End Sub
I have a drop down to select a product. With a macro attached to a button, the macro filters an item list based on the selected product. (Similar to this thread as a start point: The form is locked, but the drop down cell for selection is not (obviously).
When selecting a value like "Fruit" or "Dairy", it works great. When trying to select blank it fails -- MS VB "Run time error '1004': ShowAllData method of Worksheet class failed". With the form locked, I also noticed in the Data ribbon - Sort & Filter group - "Clear" option is gray.
The macro text follows, where C9 is my select-box-result-cell for product (<blank>,Fruit, Dairy) and my filtered data is in cell range A13 to H250:
Sub Product_List()
'
' Product_List Macro
' If Pricing for Product is blank, it unfilters all; if not blank, filters for matches in Col B
'
If Range("C9") = 0 Then
ActiveSheet.ShowAllData
Range("A1").Select
Else
Range("A13:H250").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("C8:C9"), Unique:=False
End If
End Sub