Private Sub to looking at two different cell changes

EdwardSurrey

New Member
Joined
May 13, 2015
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Is there a way to have a private sub that runs different macros based on different cell changes?

The below code only executes the HideRows macro when I change the value in C11. It will not execute ClearData macro when I change C10. Is there a way to make it work?

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C11")) Is Nothing Then HideRows
Exit Sub
If Not Intersect(Target, Range("C10")) Is Nothing Then ClearData
End Sub


Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Yes, get rid of the "Exit Sub" row.
Once it hits that, it will never get to the next row.
 
Upvote 0
Solution
Take out the Exit Sub? It's stopping the C10 test from ever being executed.
 
Upvote 0
Thanks. I thought I already tried that! Somehow it's now working. Strange :)
 
Upvote 0
You are welcome.
Glad we could help!

Typically, you see the "Exit Sub" line in code where you are checking for a particular condition, and if that condition is NOT met, you want to exit the code without doing anything else.
 
Upvote 0

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