Macro to hide/unhide rows based on cell value

PuntingJawa

Board Regular
Joined
Feb 25, 2021
Messages
140
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Sweet! Thanks again. It works nicely and I can remove the button.
Before:
1712507614797.png

After
1712507661257.png
 
Upvote 0

Forum statistics

Threads
1,215,204
Messages
6,123,630
Members
449,109
Latest member
Sebas8956

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