Hide Blank Rows in a column

grogmi1

New Member
Joined
Sep 17, 2010
Messages
49
Hi,

I am looking for VB code that will hide any blank rows within my list. I hve a list of numbers in column c and a seperate formula removes the staff number from the list when they have been give a job. The list of staff is seperate on sheet 4 and their numbers are in column c. I have been tinkering about with the code below which can hide individual rows but I need something that will search down column C and hide any rows which are blank. Any help would be much appreciated

Code:
Private Sub Worksheet_Calculate()
On Error GoTo stoppit
Application.EnableEvents = False
With Me.Range("c:c")
If .Value = "" Then
.EntireRow.Hidden = True
Else
.EntireRow.Hidden = False
End If
End With
stoppit:
Application.EnableEvents = True
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
[COLOR="Blue"]Sub[/COLOR] HideC()
    Columns("C:C").Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = [COLOR="Blue"]True[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Thanks for the quick reply, sorry I should have been a bit more specific. The list of staff numbers starts at row 5 in column C as i have row headers and the panes frozen, I have tried the code you gave me and it only hides the blank rows 1 to 4 in column C. I should also let you know I'm no VB expert !!

Thanks again
 
Upvote 0
Sorry also, just to add, the cells in column C contain formulas, not sure if that make any difference
 
Upvote 0
You mean that there are formulas which produce empty string?
 
Upvote 0
Yeah, sorry!!

The formulas in column C look to a different sheet to see if a staff number has been used, if it has then it "blanks" the cell out

Thanks
 
Upvote 0
Code:
[COLOR="Blue"]Sub[/COLOR] HideC()
    
    [COLOR="Blue"]Dim[/COLOR] lastRow [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]Long[/COLOR], rng [COLOR="Blue"]As[/COLOR] Range
    
    lastRow = Cells(Rows.Count, "C").End(xlUp).Row
    
[COLOR="seagreen"]    ' Insert dummy row.[/COLOR]
    Rows(1).Insert
    
    [COLOR="Blue"]With[/COLOR] Range("C1")
        .Value = "ABC"
        .AutoFilter Field:=1, Criteria1:="="
        [COLOR="Blue"]Set[/COLOR] rng = Range("C2:C" & lastRow + 1).Cells.SpecialCells(xlCellTypeVisible)
        [COLOR="Blue"]If[/COLOR] [COLOR="Blue"]Not[/COLOR] rng [COLOR="Blue"]Is[/COLOR] [COLOR="Blue"]Nothing[/COLOR] [COLOR="Blue"]Then[/COLOR]
            .AutoFilter
            rng.EntireRow.Hidden = [COLOR="Blue"]True[/COLOR]
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]If[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    
[COLOR="seagreen"]    ' Turn off autofilter, if any.[/COLOR]
    [COLOR="Blue"]With[/COLOR] ActiveSheet
        [COLOR="Blue"]If[/COLOR] .AutoFilterMode [COLOR="Blue"]Then[/COLOR] .AutoFilter.Range.AutoFilter
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    
[COLOR="SeaGreen"]    ' Delete dummy row.[/COLOR]
    Rows(1).Delete
    
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Last edited:
Upvote 0
Hi Sektor,

Thanks again, when I use the code from you last post it hides everything (blank cells and cells with staff numbers in) up to row 182?
Any ideas?

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

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