+ Reply to Thread
Results 1 to 3 of 3

Color Header Specific Color Only to End of Text

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    81

    Color Header Specific Color Only to End of Text

    I have a header (row 1) in my worksheets that I need to fill with a specific color (ColorIndex 13 – purple color), but only in the cells in that row that have text. For example, sometimes the header will go to Col H, sometimes to Col K, etc. Trying to write a macro that will only fill the row with color with cells that contain text.

    Help is much appreciated, thanks!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Color Header Specific Color Only to End of Text

    Hello MSmithson,

    This will color only the cells in row 1 that have text.
    Sub ColorHeader()
    
      Dim Cell As Range
      
        For Each Cell In Range("A1", Cells(1, Columns.Count).End(xlToLeft))
          If Cell <> "" Then Cell.Interior.ColorIndex = 13
        Next Cell
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Color Header Specific Color Only to End of Text

    Couldn't you use Conditional Formatting rather than a macro?

    Select Row 1
    Conditional Formatting > Use a formula ...

    Formula:-
    =ISTEXT(A$1)
    Apply your format colours to fill and font as required.

    ColorIndex 13 – purple is rather dark, you might want to make font formatting
    colour:= white.

    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1