Excel VBA Format all cells with same value in a column yellow fill

Posted on 2014-10-28
Medium Priority
Last Modified: 2014-10-29

What Excel VBA code would I use to find and format all cells in column B
with the same value (e.g. xyz) with a background fill colour of yellow
Question by:Murray Brown
  • 3
  • 3
LVL 54

Expert Comment

ID: 40410060

pls try

Sub Macro()
strText = "xyz"

With Application.ReplaceFormat.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
Range("B:B").Replace strText, strText, xlWhole, , , , , True

End Sub

Open in new window


Author Comment

by:Murray Brown
ID: 40410101
Hi. Does that format just column B
LVL 54

Expert Comment

ID: 40410165
Yes it should

line 11

Range("B:B"). etc.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

by:Murray Brown
ID: 40410266
Hi. It looks like that line just replaces values not formats in the column, or am I missing something
LVL 54

Accepted Solution

Rgonzo1971 earned 2000 total points
ID: 40410343
The True at the end is for Replace format

Is there Conditional Formatting  in these cells?

Author Closing Comment

by:Murray Brown
ID: 40410349
great thanks. No conditional formatting

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question