Macro to hide/unhide rows based on cell value

PuntingJawa

Board Regular
Joined
Feb 25, 2021
Messages
158
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I'm looking for a macro to hide and unhide rows in two specific ranges. If the value in each of the following ranges is blank, I would like it to hide that whole row. I've seen several macro's function automatically, but I plan to use a button. I've tried several variations, but they have not functioned well.
C21:C55 and C60:C94
 
You cannot imbed procedures (macros) inside other procedures.
However, you can call them. So you can keep your original code, and then just add this one:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range

'   See if an update is made to cell R18
    Set rng = Intersect(Target, Range("R18"))

'   If not, exit sub
    If rng Is Nothing Then Exit Sub

'   Call Hide Rows procedure
    Call MyHideRows

End Sub
Note: "Worksheet_Change" event procedures MUST be placed in the Sheet module of the sheet you want to run them against in order to run automatically.
 
Upvote 1

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Sweet! Thanks again. It works nicely and I can remove the button.
Before:
1712507614797.png

After
1712507661257.png
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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