Solved Hide rows if value in column C is 0

November 24, 2016 at 11:37:09
Specs: Windows 64
Hi Guys,
need to work out a VBa for the following

Rows 9 to 50 have data in most fields
If a cell in Column C, Row 15 has a value of '0' and Column C, Row 31 has a value of '0', I need to be able to hide those Rows.
Is it possible ? and if so, how do I go about it

Thanks
Tony


See More: Hide rows if value in column C is 0

Report •

#1
November 24, 2016 at 15:41:10
Have you considered using the Filter feature?

You can use a Filter to show rows not equal to 0.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
November 25, 2016 at 09:15:26
Hi DD03,
Thanks for the push in the filter direction, but not too happy with what I need to do. I found the following bit of code, to which i have added a few bits. However I find this rather slow.
The code was put online quite away back. Could you have a look and see what may be making it slow to perform
Sub HideRows99()

    Application.ScreenUpdating = False
        
    Sheets("Sheet1").Cells.Select
        Selection.EntireRow.Hidden = False

    Dim cell As Range
    For Each cell In Sheets("Sheet1").Range("A9:A120")
    If (cell.Value) = "0" Then
    cell.EntireRow.Hidden = True
    End If
    Next
    
    Sheets("Sheet1").Range("C2").Select
    
    Application.ScreenUpdating = True
    
End Sub

Just open a new workbook and on Sheet 1 enter values in column A of 1 or 0
Run the code and see how slow it is.

Tony


Report •

#3
November 25, 2016 at 20:26:00
✔ Best Answer
I don't know what you consider slow but it took less than one second to run.

I added 2 instructions to write the start and end time in 2 cells and they both show the
exact same time. I then put zero's in A9:A10000 so the code had to hide thousands of rows. That took about 3 seconds.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Related Solutions

#4
November 25, 2016 at 23:02:48
Hi DD03,
Thanks for having a look, I also ran the above in a new workbook , this the only workbook open and quick as a flash, it worked
I have to assume that because of the amount of formula in the actual workbook, the one I sent you but with an additional two worksheets that pulls in lots of data, this slows down the process, to about 45 secs
I can live with it as the reports are for the yearend
Again thanks for having a look, and have a god Thanksgiving
Tony

Report •

Ask Question