run macro automatically when dropdown list value is changed

andrismeister

New Member
Joined
Apr 10, 2013
Messages
5
Dear all,

I'm kind of new here - and to excel macros as well -, and eventhough I was trying to look up solution here on mrexcel forums, I couldn't find an appropriate adn that's why I've opened a new thread for it.

So the case is:

I have a sheet with 12 rows which I want to work with.

I have made a dropdown validation list of four values (A, B, C, and D) which works fine.

What I would like to do is:
- when I select a value from the dropdown list, I'd like a macro to run and hide 9 rows from the 12, but leave the 3 rows to be unhidden.

I have already written a macro, which does it's job, the only problem is that I was only able to find a solution to trigger it by clicking on a button after selecting the desired value from the dropdown list.

But instead of triggering it by clicking on the button, I'd like the macro to run automatically when the dropdown list cell has changed.

My macro so far is:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("A8")) Is Nothing Then Macro
Sub selectsequencemodel()
Rows("10:21").EntireRow.Hidden = False
If Range("A8") = "A" Then
Rows("10:12").EntireRow.Hidden = False
Rows("13:21").EntireRow.Hidden = True
End If
If Range("A8") = "B" Then
Rows("10:12").EntireRow.Hidden = True
Rows("16:21").EntireRow.Hidden = True
End If
If Range("A8") = "C" Then
Rows("10:15").EntireRow.Hidden = True
Rows("19:21").EntireRow.Hidden = True
End If
If Range("A8") = "D" Then
Rows("10:18").EntireRow.Hidden = True
End If
End Sub

cell A8 is the place of the dropdown list.

If you need additional information, let me know.

Thank you for your help in advance.

Regards,

Andrew
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,207,012
Messages
6,076,148
Members
446,187
Latest member
LMill

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