Need a Macro designed to hide rows that have nothing in column C

bawils

New Member
Joined
Apr 4, 2013
Messages
2
I need help and fast! I need a macro that will hide all rows which have nothing in colum C. Important: I add rows on a regular/daily basis so it needs to account for this too. The rows start at row 5 and go to row 104 right now, but remember, I add new rows daily! Can anyone help? Noone seems to be able to help me with this and it is the last element of a major excel project. The workbook will be locked too, do we need to incorparate a unlock/lock into it?
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I don't typically protect my sheets, so the unprotecting and protecting code may need to be modified to suit your needs.. I just merely recorded the default values to plug into this. The remainder should work as expected though.

Code:
Sub HideEmptyCrows()

ActiveSheet.Unprotect
Dim i As Long
Dim lr As Long

lr = Range("C65536").End(xlUp).Row
For i = lr To 5 Step -1
    If Cells(i, "C") = "" Then
        Rows(i).Delete Shift:=xlUp
    End If
Next i
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
 
Upvote 0
Change "password" to your password if the sheet is password protected and change ActiveSheet to suit.
Please note that the code posted by rjwebgraphix deletes the rows rather than hide them

Code:
Sub HideMe()
    Dim cell As Range
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect Password:="password"
    Cells.EntireRow.Hidden = False
    For Each cell In Range("C5:C" & Cells(Rows.Count, "C").End(xlUp).Row)
        If cell = "" Then cell.EntireRow.Hidden = True
    Next cell
    ActiveSheet.Protect Password:="password"
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Change "password" to your password if the sheet is password protected and change ActiveSheet to suit.
Please note that the code posted by rjwebgraphix deletes the rows rather than hide them

Code:
Sub HideMe()
    Dim cell As Range
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect Password:="password"
    Cells.EntireRow.Hidden = False
    For Each cell In Range("C5:C" & Cells(Rows.Count, "C").End(xlUp).Row)
        If cell = "" Then cell.EntireRow.Hidden = True
    Next cell
    ActiveSheet.Protect Password:="password"
    Application.ScreenUpdating = True
End Sub

Thank You Mark858: I Just realized I also need a way (Macro) to undo it!? Is that possible and if so...How?
 
Upvote 0
Thank You Mark858: I Just realized I also need a way (Macro) to undo it!?

One way is to use similar Syntax
Code:
Sub UnHideMe()
    Dim cell As Range
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect Password:="password"
    Range("C5:C" & Cells(Rows.Count, "C").End(xlUp).Row).EntireRow.Hidden = False
    ActiveSheet.Protect Password:="password"
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Ummm... no final response and cross-posted without a link...Noted
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,184
Members
448,949
Latest member
keycalinc

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