Hide rows, if a cell value automatically changes (based on a formula)

vivek456

New Member
Joined
Feb 28, 2018
Messages
5
Hello - I badly need some help. Can someone help me please?

The below macro works only if there is a manual action on cell C5. I am keen to initiate the below macro, if cell C5 automatically changes because of a formula in cell C5. Any feedback on this would be much appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)ActiveSheet.ActivateIf Not Application.Intersect(Range("C5"), Range(Target.Address)) Is Nothing Then Select Case Target.Value Case Is = "Canada": Rows("19:25").EntireRow.Hidden = True Rows("7:18").EntireRow.Hidden = False Case Is = "India": Rows("19:25").EntireRow.Hidden = False Rows("7:18").EntireRow.Hidden = True End SelectEnd IfEnd Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Range("C5").Value
    Case "Canada"
        Rows("19:25").EntireRow.Hidden = True
        Rows("7:18").EntireRow.Hidden = False
    Case "India":
        Rows("19:25").EntireRow.Hidden = False
        Rows("7:18").EntireRow.Hidden = True
End Select
End Sub
 
Upvote 0
Thank you very much. Appreciate it.

If I wanted to extend this logic based on the value that automatically changes in C5, would I be able to protect (non editable)/unprotect a column F4:F10?

Is there a way to do this?

Thank you once again for this.
 
Upvote 0

Forum statistics

Threads
1,216,998
Messages
6,133,943
Members
449,849
Latest member
nnnyyy

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