VBA Code to Automatically Hide/Unhide Rows based on Formula Display Value of 0

Etak28

New Member
Joined
Jan 13, 2023
Messages
6
Office Version
  1. 2019
Platform
  1. MacOS
Hello all!

Brand new to this forum and to VBA code so please bear with me.

I've searched and tried code from various threads on here and none of them have worked for me even though this topic has been discussed quite a few times.

What I'm trying to do is automatically hide rows 10:27 on my Sheet 1 if the displayed formula value in cells C10:C27 = 0.
If the displayed formula value is anything greater than 0 in cells C10:C27, then I'd like those rows to be automatically displayed.

For some background, cells C10:C27 use a formula to automatically pull data from 1 of 5 sheets depending on which one is used. Not sure if it's useful, but the cell that initiates that change on every sheet is Cell B6.

Please let me know if any other pertinent information is needed.
Appreciate any and all help!
 
I hope I have understood. Delete everything and try this:

VBA Code:
Private Sub Worksheet_Activate()
  Dim i As Long, n As Long
  Dim rng As Range
 
  Application.ScreenUpdating = False
 
  Set rng = Range("C10:C27")
  n = WorksheetFunction.CountIf(rng, 0)
  If n = rng.Count Then
    rng.Rows.Hidden = False
  Else
    For i = 10 To 27
      Rows(i).Hidden = Range("C" & i).Value = 0
    Next
  End If
 
  Application.ScreenUpdating = True
End Sub
That's it!!
Thank you so much for your help today, I really appreciate it!
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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