• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need formula to format cells

gspreeman

New Member
I need to include in one of my macros code that will look in Column A for a cell that contains "TOTAL SALES" and then colors the interior of the cell a medium gray, applies Bold to the font, and applies a line on top and on the bottom of the cell. After this is done, I then need to apply that same formatting to the cells in that same row up to column R. Help! Thanks in advance.
 
gspreeman
Please reread Forum Rules:
especially How to get the Best Results at Chandoo.org
After that, ask from Yourself
- Could You do something better to get answers?
 
Here is what I have so far and, it kind of works but, I noticed that it applies the font change and interior color change to all cells that contain the word Sales. And, it doesn't include the top and bottom borders I need. I am new to scripting so, I'm not sure if formatting adjacent cells with the same formatting would be part of the same loop or a second establishment of ranges. Again, thank you in advance for any help you might be able to offer.

>>> use code - tags <<<
Code:
With Range("A1:A300").FormatConditions.Add(xlTextString, TextOperator:=xlContains, String:="Sales")
With .Font
.Bold = True
.Color = vbBlack
End With
.Interior.ColorIndex = 16
End With
 
Last edited by a moderator:
gspreeman
Okay
... the title could be better too.
Did You continue to read other sentence from How to get the Best Results at Chandoo.org -part?
How could others test/verify something without ... ?
 
try:
Code:
With Range("A1:R300").FormatConditions
  .Delete
  With .Add(Type:=xlExpression, Formula1:="=ISNUMBER(FIND(""TOTAL SALES"",$A1))")
    .Font.Bold = True
    .Borders(xlTop).LineStyle = xlContinuous
    .Borders(xlBottom).LineStyle = xlContinuous
    .Interior.Color = 11184814
  End With
End With
 
Back
Top