VBA to hide Rows that are Zero

Elle Mc

New Member
Joined
Jan 29, 2019
Messages
4
Hi All,

I am hoping someone can help with the below code. Problem seems to be at the "if" part of the code but cannot see my issue. Thanks!


Sub HideRows()

Dim sheetNamesArray
Dim rangesArray

Application.ScreenUpdating = False
Application.Calculation = xlManual

Rows("4:268").Hidden = False

'Array with the names of all of your sheets
sheetNamesArray = Array("SCM 43200", "MatHand 43223", "Ship 43203")
'Array with all of your ranges
rangesArray = Array("T4:T87", "T92:T175", "T185:T268")

'Go through each sheet in the array
For Each sheetName In sheetNamesArray
'Go to each range in the sheet
For Each rangeName In rangesArray
'Hide Lines with Zero value or Blank
For Each cell In rangesArray

If cell.Value = 0 Then Rows(cell.Row).Hidden = True
Next

Next
Next


End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi & welcome to MrExcel
How about
Code:
Sub HideRows()

Dim sheetNamesArray
Dim rangesArray

Application.ScreenUpdating = False
Application.Calculation = xlManual


'Array with the names of all of your sheets
sheetNamesArray = Array("pcode", "List", "a1")
'Array with all of your ranges
rangesArray = Array("T4:T87", "T92:T175", "T185:T268")

'Go through each sheet in the array
For Each Sheetname In sheetNamesArray
   With Sheets(Sheetname)
      .Rows("4:268").Hidden = False
      'Go to each range in the sheet
      For Each RangeName In rangesArray
         'Hide Lines with Zero value or Blank
         For Each cell In .Range(RangeName)
            If cell.Value = 0 Then .Rows(cell.Row).Hidden = True
         Next
      Next
   End With
Next


End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,833
Messages
6,181,237
Members
453,026
Latest member
cknader

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