Hide & unhide rows

timesareGMT

New Member
Joined
Aug 19, 2011
Messages
26
Hi all,

I create a calculation page on which the final result displays in cell D21.

How can I set up a macro to:
1. If D21 < 0.5, hide rows 22 to 28.
2. If D21 > 0.5, unhide rows 22 to 28.

And, how can I prevent the assigned macro from being stopped running when I password protect the spreadsheet?

Thanks a lot.
 
I think this Change event code may be what you are looking for...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Cell As Range
  If Not Intersect(Range("D21").Precedents, Target) Is Nothing Then
    Rows("22:28").Hidden = Range("D21").Value > 0.5
  End If
End Sub
Just to reiterate, this code goes in the worksheet module for the worksheet you want to have this functionality on (it does not go in a standard module). To get to this module, right click the name tab at the bottom of the worksheet you want to have this functionality and click on "View Code" on the popup menu that appears... copy/paste the code into the code window that just opened up.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

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