How to make code run when a cell is selected

Lorna

New Member
Joined
Mar 12, 2009
Messages
19
I have a sheet which contains four dependent dropdown boxes. The first three work just fine using the Indirect function and Named Ranges. The fourth dropdown contains illegal characters and there is so much data that is seems too cumbersome to use the VLookUp option to work around it. So what I'm trying to do is to use an advanced filter to generate the data based upon selections from the previous three dropdowns. The data that it's filtering is located on another sheet called Validation Lists. I created a macro to do this and attached it to a button by the fourth dropdown and it works just fine to filter the data appropriately for the dropdown. This seems like a Mickey Mouse way to do it, however.

What I want to have happen is that when the user clicks on cell C23 where the third dropdown located, I want the code to run that filters the data for the fourth dropdown located in cell C27. (This dropdown uses as its source a range called OtherFiltered which refers to the column of extracted data on the Validation Lists sheet where the filtered data is located.)

The code I have attached for the worksheet where the dropdowns are located doesn't produce any errors, it just doesn't do anything but clear the contents of all the dropdowns (as it's supposed to) and clears the previously range of previously extracted (if there is any) on the Validation Lists sheet. The section of code that performs the advanced filter never runs. What am I doing wrong?!!!

Following is the code I'm trying to use. Any help as to why it's not working would be greately appreciated.


Private Sub Worksheet_Change(ByVal Target As Range)
'Clears contents of dependent dropdown boxes when data changes
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
'
'Runs only when value in Other Criteria dropdown box changes
On Error Resume Next
If Not Intersect(Target, Range("C23")) Is Nothing Then
Application.Goto Reference:="OtherClearRange"
Selection.ClearContents
Range("OtherData").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("OtherCriteria"), CopyToRange:=Range("OtherExtract"), Unique:=True
Sheets("Food Rotation").Select 'Location of fourth dropdown
Range("C27").Select
End If
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top