Hide rows with conditions macro

pincivma

Board Regular
Joined
Dec 12, 2004
Messages
203
Hi again

With the help of this forum, I created a macro that hides rows. What I want the macro to do is to hide rows from columns 7 to 10 whose cells have a white background (no color) and at the same time the font is black
Below is my code. I do not get an error but nothing happens when I execute the macro. The rows are not hidden at all. What did I do wrong in the macro below?. There is something wrong. The problem is with the the line in red below

If Cells(x, 7).Interior.TintAndShade = 0 And Cells(x, 7).Font.ColorIndex = Automatic And Cells(x, 8).Interior.TintAndShade = 0 And Cells(x, 8).Font.ColorIndex = Automatic _
And Cells(x, 9).Interior.TintAndShade = 0 And Cells(x, 9).Font.ColorIndex = Automatic And Cells(x, 10).Interior.TintAndShade = 0 And Cells(x, 10).Font.ColorIndex = Automatic Then


Cells(x, 7).Interior.TintAndShade = 0 (this code checks to see if the Cell has no color) and Cells(x, 7).Font.ColorIndex = Automatic (this code checks to see if the font is black). But I believe that these 2 lines of code is wrong. So can someone out there give me the correct code? Thanks

Sub Test1()
Application.ScreenUpdating = False

Range("A" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Offset(0, 6).Select
ActiveCell.FormulaR1C1 = "."
Range("G1").Select
Do
x = ActiveCell.Row
If Cells(x, 7).Interior.TintAndShade = 0 And Cells(x, 7).Font.ColorIndex = Automatic And Cells(x, 8).Interior.TintAndShade = 0 And Cells(x, 8).Font.ColorIndex = Automatic _
And Cells(x, 9).Interior.TintAndShade = 0 And Cells(x, 9).Font.ColorIndex = Automatic And Cells(x, 10).Interior.TintAndShade = 0 And Cells(x, 10).Font.ColorIndex = Automatic Then
Rows(x).Hidden = True
End If
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.FormulaR1C1 = "."
End Sub
 
Oh OK. Thanks for your help. I'm still learning VBA so for me it is going to be trial and error in figuring things out
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I'm still learning VBA
You only stop learing VBA if you stop using VBA o_O
Even those with the most in depth knowledge still find things that they don't know from time to time (probably more frequently than some of them admit).
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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