Hide rows that are formatted a certain way

CaptainGravyBum

New Member
Joined
Dec 1, 2023
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Happy New Year all!

I've had a few days away from the office and it appears my brain will not function anymore.
I have a simple excel checklist which when a row is complete it will conditionally format as green. I want the users to activate a macro when they are finished using the sheet and it will hide all rows that are green.
Trying to avoid using an autofilter because it can be removed too easily.
I know it's simple, but I'm not getting there fast.
Any help greatly appreciated.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The only way to do that automatically without using Filters is to use VBA.
Are you open to using VBA?

Also, what exactly is your Conditional Formatting Rule that currently turns these rows green?
We will probably want to use the same logic in the VBA code.
 
Upvote 0
The only way to do that automatically without using Filters is to use VBA.
Are you open to using VBA?

Also, what exactly is your Conditional Formatting Rule that currently turns these rows green?
We will probably want to use the same logic in the VBA code.
Hi @Joe4 ,
yes, VBA is what I'm after. Basically, if a cell is populated with any text in column L, then the whole row turns green.
 
Upvote 0
Probably like this

VBA Code:
Sub jec()
On Error Resume Next
Columns("L").SpecialCells(2).EntireRow.Hidden = True
End Sub
 
Upvote 0
Go to the sheet you want to apply this to, right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the VB Editor box that shows up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if multiple cells updated at once
    If Target.CountLarge > 1 Then Exit Sub
    
'   Only run if column L is manually updated and is not empty
    If (Target.Column = 12) And (Target <> "") Then
'       Hide row
        Rows(Target.Row).Hidden = True
    End If
    
End Sub
This should automatically hide the row as column L is manually updated.
 
Upvote 0
Go to the sheet you want to apply this to, right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the VB Editor box that shows up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if multiple cells updated at once
    If Target.CountLarge > 1 Then Exit Sub
   
'   Only run if column L is manually updated and is not empty
    If (Target.Column = 12) And (Target <> "") Then
'       Hide row
        Rows(Target.Row).Hidden = True
    End If
   
End Sub
This should automatically hide the row as column L is manually updated.
Thanks, that works well.
However, is there a way to convert this so it can be run on it's own in a module? Only reason I ask is that I need the user to hide completed at the end of the day rather than it happening as the day goes on. I tried running this manually and it fails with an object error.
 
Upvote 0
Thanks, that works well.
However, is there a way to convert this so it can be run on it's own in a module? Only reason I ask is that I need the user to hide completed at the end of the day rather than it happening as the day goes on. I tried running this manually and it fails with an object error.
Try this version then:
VBA Code:
Sub MyHideRows()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column L with data
    lr = Cells(Rows.Count, "L").End(xlUp).Row

'   Loop thought rows starting with row 2
    For r = 2 To lr
'       See if column L is not empty
        If Cells(r, "L") <> "" Then
'           Hide row
            Rows(r).Hidden = True
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 1
Solution
Try this version then:
VBA Code:
Sub MyHideRows()

    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row in column L with data
    lr = Cells(Rows.Count, "L").End(xlUp).Row

'   Loop thought rows starting with row 2
    For r = 2 To lr
'       See if column L is not empty
        If Cells(r, "L") <> "" Then
'           Hide row
            Rows(r).Hidden = True
        End If
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
Perfect!, thank you.
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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