+ Reply to Thread
Results 1 to 3 of 3

Thread: Conditional Row Formating based on one cell of the row

  1. #1
    Registered User
    Join Date
    02-10-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Conditional Row Formating based on one cell of the row

    I have an xls that has multiple worksheets and i need to run a macro that will format certain rows on each sheet. The rows are always different but the columns are all the same B-E on each sheet. The condition to look for is the word "Total", if it has that word anywhere on the row then we need the row to be formatted between Col B-E (Bold and a top line). Is there a good macro that can help us do this? Tried for a week and nothing is working.
    Last edited by Aredmon25; 02-15-2012 at 08:37 AM.

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

    Re: Conditional Row Formating based on one cell of the row

    Hello Aredmon25,

    Welcome to the Forum!

    This macro will check columns "B:E" of each sheet for any occurrence of the word "total". When found, a border is added to the top of the cells and the cells font is set to bold.
    Sub FormatTotals()
    
        Dim Data As Variant
        Dim I As Long
        Dim Rng As Range
        Dim Text As String
        Dim Wks As Worksheet
        
            For Each Wks In Worksheets
                Set Rng = Wks.Range("B1:E" & Wks.UsedRange.Rows.Count)
                Data = Rng.Value
                    For I = 1 To UBound(Data)
                        Text = Join(WorksheetFunction.Index(Data, I, 0))
                        If UCase(Text) Like "*TOTAL*" Then
                           Rng.Rows(I).Font.Bold = True
                           With Rng.Rows(I).Borders(xlEdgeTop)
                               .Weight = xlMedium
                               .LineStyle = xlContinuous
                           End With
                        End If
                    Next I
            Next Wks
        
    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
    Registered User
    Join Date
    02-10-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Conditional Row Formating based on one cell of the row

    Thanks! We will give it a shot and see if it works. Thanks!!

+ 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.2.0