Consulting

Results 1 to 8 of 8

Thread: Solved: Find ALL Cell Fill Colors and Make them One Color

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Solved: Find ALL Cell Fill Colors and Make them One Color

    I've got peach and green and all sorts of cell fill colors in use.

    Without affecting those that are conditionally formatted, I'd like to find all cells filled with color and make them all the same color... any color you like is fine; well...except black.

    ~Anne Troy

  2. #2
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    This could be slow if the UsedRange and/or the number of worksheets is large [vba]Sub ChangeCellColors_OneWorksheet()
    Dim Cell As Range
    Application.ScreenUpdating = False
    For Each Cell In ActiveSheet.UsedRange
    If Cell.Interior.ColorIndex <> xlColorIndexNone Then
    Cell.Interior.ColorIndex = 35
    End If
    Next
    Application.ScreenUpdating = True
    Set Cell = Nothing
    End Sub

    Sub ChangeCellColors_EntireWorkBook()
    Dim Cell As Range, Sheet As Worksheet
    Application.ScreenUpdating = False
    For Each Sheet In Worksheets
    Sheet.Activate
    For Each Cell In ActiveSheet.UsedRange
    If Cell.Interior.ColorIndex <> xlColorIndexNone Then
    Cell.Interior.ColorIndex = 35
    End If
    Next Cell
    Next Sheet
    Application.ScreenUpdating = True
    Set Sheet = Nothing
    Set Cell = Nothing
    End Sub[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Works terrific, John. Could you possibly add a status bar message to tell us what sheet (or what sheet number) it's on? Would love that!!
    ~Anne Troy

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    John shows offline, I'll help him out ...

    [vba]Sub ChangeCellColors_EntireWorkBook()
    Dim Cell As Range, Sheet As Worksheet
    Application.ScreenUpdating = False
    For Each Sheet In Worksheets
    Application.StatusBar = "Working on " & Sheet.Index & " of " & Worksheets.Count & " - " & Sheet.Name
    For Each Cell In Sheet.UsedRange
    If Cell.Interior.ColorIndex <> xlColorIndexNone Then
    Cell.Interior.ColorIndex = 35
    End If
    Next Cell
    Next Sheet
    Application.ScreenUpdating = True
    Application.StatusBar = False
    Set Sheet = Nothing
    Set Cell = Nothing
    End Sub[/vba]

  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Done [vba]Sub ChangeCellColors_EntireWorkBook()
    Dim Cell As Range, Sheet As Worksheet, N As Long
    Application.ScreenUpdating = False
    N = 1
    For Each Sheet In Worksheets
    Sheet.Activate
    For Each Cell In ActiveSheet.UsedRange
    If Cell.Interior.ColorIndex <> xlColorIndexNone Then
    Cell.Interior.ColorIndex = 35
    End If
    Next Cell
    Application.StatusBar = "Progress: " & N & _
    " Sheets done" & " out of " & Worksheets.Count
    DoEvents
    N = N + 1
    Next Sheet
    Application.ScreenUpdating = True
    Set Sheet = Nothing
    Set Cell = Nothing
    End Sub[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  6. #6
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi Zack, I musta come online & posted at same time as you
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  7. #7
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    LOL. Thanks!!!
    ~Anne Troy

  8. #8
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    LOL! Sorry John, didn't mean to step on your toes buddy.

Posting Permissions

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