hiding rows based on conditional format of background colour

fry

Active Member
Joined
Apr 25, 2007
Messages
411
Hi All

I'm struggling with this. I found this code that seemed to be what I want but when I ran it, it did absolutely nothing?????

Code:
Sub test() 
Dim LR As Long      'Last Row 
Dim RN As Integer   'Row Number 

LR = Cells(Rows.Count, "J").End(xlUp).Row 

Application.ScreenUpdating = False 

    For RN = 1 To LR 
    If Cells(RN, "J").Interior.ColorIndex = 37 Then Cells(RN, "J").EntireRow.Hidden = True 
    Next RN 
    
 Application.ScreenUpdating = True 
  
End Sub

I have an increasing number of rows that are normally formatted unless a value is entered in a particular cell, in which case the whole row is formatted in a different colour. I need a bit of code that will hide all the rows in that colour....

Anyone like to help with this??? :)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Why do you need code?

Couldn't you just use a filter with the criteria based on that used for the conditional formatting?

PS The reason the code doesn't work is because conditional formatting doesn't really change the color.:)
 
Upvote 0
Change your code to look at the same condition as your conditional format.
Like Norie said, Conditional formating does not set a property in the cell that can be used outside of conditional format, it just changes the view.
 
Upvote 0
Hi Norie

I've managed to sort it another way........BUT............I now can't get the hidden rows back???

Help.... :(

Here's the code that works
Code:
Sub test()
Dim LR As Long      'Last Row
Dim RN As Integer   'Row Number

LR = Cells(Rows.Count, "B").End(xlUp).Row

Application.ScreenUpdating = False

    For RN = 1 To LR
    If IsEmpty(Cells(RN, "J")) = False Then Cells(RN, "J").EntireRow.Hidden = True
    Next RN
    
 Application.ScreenUpdating = True
  
End Sub
 
Upvote 0
Phew........panic over..........I changed 'false' to 'true' when I should have changed 'true' to 'false'...........DOH!!!!

Thanks for your help anyway... :)
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,007
Members
448,935
Latest member
ijat

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