How to hide/unhide multiple rows where the result is 0 in column A

RobbieNZ

New Member
Joined
Aug 17, 2010
Messages
21
Hi there,
I have this code but it only hides rows based on a single cell result.
I really need to hide multiple rows based on result in column A (so this changes)

I have honestly spent the whole morning looking for and trying different options from different forums but keep getting erros. As I am a neophyte when it comes to macros I have no idea how to remedy the errors in the code I was trying.
So here is what I want to be able to do

I want to make code activate by control button.
Only check rows 67-176
if column A between rows 67-176 is 0 then hide if not unhide (if hidden) or leave. NB: the 0 is the result of a formula.

my current code below only calcs on result of one cell.
Thanks in advance for your help!!


Code:
'Private Sub Worksheet_Calculate()
'Dim myresult As String
'Dim MyResult1 As String
'Dim MyResult2 As String
'Application.ScreenUpdating = False
'Application.EnableEvents = False
 
'Rows("1:" & Worksheets("Q U O T E").UsedRange.Rows.Count).EntireRow.Hidden = False
'myresult = Worksheets("Q U O T E").Cells(99, 1).Value 'Controls'
'MyResult1 = Worksheets("Q U O T E").Cells(72, 1).Value 'Valve Chamber'

''''''''''''''''''''''''''''''''''''''''''''''''''
'Select Case MyResult1
''Case "", "None", "0"
'Rows("72:93").EntireRow.Hidden = True
'Rows("167:167").EntireRow.Hidden = True
'End Select
'Select Case myresult
'Case "", "None", "0"
'Rows("99:114").EntireRow.Hidden = True
'End Select
'Application.EnableEvents = True
'Application.ScreenUpdating = True

'End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Put this in the worksheet module that has your command button...

Code:
Private Sub CommandButton1_Click()

    Dim cell As Range

    Application.ScreenUpdating = False
    
    With Worksheets("Q U O T E")
    
        .Rows("67:176").Hidden = False
        
        For Each cell In .Range("A67:A176")
        
            If Not IsEmpty(cell) And cell.Value = 0 Then cell.EntireRow.Hidden = True
            
        Next cell
    
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Hi,
Thanks for your response:)

I did as you suggested but get a run time error 13 type mismatch
on debug it highlights

Code:
 If Not IsEmpty(cell) And cell.Value = 0 Then cell.EntireRow.Hidden = True

This is where being new I have no idea what the heck it means. and the help just confuses me further
 
Upvote 0
Do any of your formulas in A67:A167 produce an error value?

If yes, this will hide cells with error values as well.

Code:
Private Sub CommandButton1_Click()

    Dim cell As Range

    Application.ScreenUpdating = False
    
    With Worksheets("Q U O T E")
    
        .Rows("67:176").Hidden = False
        
        On Error Resume Next
        For Each cell In .Range("A67:A176")
            
                If Not IsEmpty(cell) And cell.Value = 0 Then cell.EntireRow.Hidden = True
           
        Next cell
        On Error GoTo 0
    
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,694
Messages
6,126,258
Members
449,307
Latest member
Andile

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