run macro when a data validation list is changed

bluefish44

Board Regular
Joined
Apr 3, 2009
Messages
190
Hi all, I need a simple piece of code to run when a data validation list is changed in cell E2. I have right clicked the correct tab and added this code below, and selected Worksheet and Change from the 2 dropdown boxes. It seems like I am doing this correctly from other posts on the subject, but when I enter the dropdown list in cell E2 and make a change, the code doesn't run. I am using excel 2010. Thanks in advance for any suggestions (my VBA skills are a bit shaky, but my code runs fine when I run it as a separate macro - just the worksheet change Event doesnt seem to work)


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$e$2" Then

Rows("6:50").Select
Selection.EntireRow.Hidden = False

Dim i As Integer

For i = 6 To 50
Rows(i).Hidden = Range("aj" & i).Value = 0
Next i

End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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