Can you AND / OR coloring in Excel via VBA

Imagine that I have rows 10 - 100 where the cells either have no color or a color of blue.

I'd like to add a macro that will turn the clear cells into red (for instance).

It would be neat if the following worked:

sheetname.range(startRow, endRow).Interior.ColorIndex = red AND blue (or red NOT blue, etc)

The thought would be if the cell was blue it'd stay blue else red.

Don't want to loop through each row and determine if it is blue and then make it red if not... have too many columns to do this with.
Sheldon LivingstonConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
The only other way that i can you can do this apart then loop is by applying filter..

Enclosed is the code for your reference where i assumed you want to apply filter on A Column on sheet1

Sub check()

    Dim lrow As Long
    Dim ws As Worksheet
    Dim r As Range
    Set ws = Sheets("Sheet1")

    lrow = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    ws.Range("A1:A" & lrow).AutoFilter Field:=1, Operator:=xlFilterNoFill
    Set r = ws.Range("A2:A" & lrow).SpecialCells(xlCellTypeVisible)

    r.Interior.ColorIndex = 3
    ws.Range("A1:A" & lrow).AutoFilter

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sheldon LivingstonConsultantAuthor Commented:
Wow!  Perfect.  Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.