I've been struggling for nearly two weeks with this problem.
I have a worksheet that contains a database of available products. On another worksheet I have a form which a salesperson will use with a customer to help find a list of products that meet certain criteria based on asking the customer four questions. The questions are answered by making selections from dropdown boxes which have been created using Data Validation.
I created a macro to perform the advanced filter that filters and copies the unique data to the OtherExtract range. The range OtherFiltered refers to the data I want for the fourth dropdown. So I set the source for the fourth dropdown to OtherFiltered. I attached a button next to the fourth dropdown and attached the macro. I click the button and everything works perfectly.
Now for my problem, how can I make this macro run without having to click a button?
I tried attaching the following code to to the Change event for the worksheet where the dropdowns are located, but nothing in the second part of the code seems to be working.
I hope I've given enough information so you can understand my problem. Any ideas as to why this is not working would be SO GREATLY appreciated.
Thanks in advance
I have a worksheet that contains a database of available products. On another worksheet I have a form which a salesperson will use with a customer to help find a list of products that meet certain criteria based on asking the customer four questions. The questions are answered by making selections from dropdown boxes which have been created using Data Validation.
- The first dropdown (cell C3) is used to select a category of products.
- The second dropdown (cell C19) uses the Indirect function to filter available products based on what category was selected.
- The third dropdown (cell C23) also uses the Indirect function to display which sizes the products are available in.
- The fourth dropdown (cell C27) is to display a list of other applicable options, depending on what was chosen in the first three boxes.
I created a macro to perform the advanced filter that filters and copies the unique data to the OtherExtract range. The range OtherFiltered refers to the data I want for the fourth dropdown. So I set the source for the fourth dropdown to OtherFiltered. I attached a button next to the fourth dropdown and attached the macro. I click the button and everything works perfectly.
Now for my problem, how can I make this macro run without having to click a button?
I tried attaching the following code to to the Change event for the worksheet where the dropdowns are located, but nothing in the second part of the code seems to be working.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'PART 1 - This code works and is used to clears contents of dependent
'dropdown boxes when data changes in previous dependent boxes.
If Not Intersect(Target, Range("C3")) Is Nothing Then
Sheets("Food Rotation").Range("C19").Value = ""
End If
If Not Intersect(Target, Range("C19")) Is Nothing Then
Sheets("Food Rotation").Range("C23").Value = ""
End If
If Not Intersect(Target, Range("C23")) Is Nothing Then
Sheets("Food Rotation").Range("C27").Value = ""
End If
'PART 2 is supposed to run only when the Other Criteria dropdown box in
'cell C27 is selected. This is the part that does not work.
If Target.Address <> "C27" Then Exit Sub
On Error Resume Next
Application.Goto Reference:="OtherClearRange"
Selection.ClearContents 'Clears range of previous extracted data
Application.Goto Reference:="OtherData"
Range("OtherData").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("OtherCriteria"), CopyToRange:=Range("OtherExtract"), Unique:=True
Sheets("Food Rotation").Select
Range("C27").Select
End If
End Sub
I hope I've given enough information so you can understand my problem. Any ideas as to why this is not working would be SO GREATLY appreciated.
Thanks in advance