+ Reply to Thread
Results 1 to 7 of 7

Macro for changing background color of the cells

Hybrid View

  1. #1
    Registered User
    Join Date
    10-21-2008
    Location
    Mumbai
    Posts
    3

    Macro for changing background color of the cells

    I will be extremely extremly thankful if anybody can help me .....

    I have an excel sheet in which many cells have a background color of Green. These cells are located all over the sheet. I want to change the background color from Green to Red not affecting the color of other cells in the sheet.


    I will be realy really thankful, as I have to do this exercise for more than 50 worksheets.......If I start doing it manually by selecting each celll with green color background and changing it to red.....you can well imagine my condition.....my life would get shorten significantly while doing this.

    Many Many Advance thanks for this.......
    Last edited by VBA Noob; 10-22-2008 at 08:49 AM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    rishuverma,

    Please read forum rules below about titles.

    You don't need code to select the cells....try

    Ctrl + H > Find what format > choose format from a green cell > options > change from within sheet to workbook and put in the replace colour

    VBA Noob
    Last edited by VBA Noob; 10-21-2008 at 08:50 AM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    This should work, but it may take a while...
    Sub x()
    Dim ws As Worksheet, rng As Range
    For Each ws In Worksheets
        For Each rng In ws.UsedRange
            If rng.Interior.ColorIndex = 10 Then rng.Interior.ColorIndex = 3
        Next rng
    Next ws
    End Sub
    EDIT: didn't know VBA Noob's suggestion.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Here an example of Find and replace. Change colour index as required

    Dim Wsht As Worksheet
    
    With Application
        .FindFormat.Clear
        .ReplaceFormat.Clear
    End With
        With Application.FindFormat.Interior
            .ColorIndex = 35
        End With
       
        Application.ReplaceFormat.Interior.ColorIndex = 19
        For Each Wsht In Worksheets
        Wsht.Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _
            xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
        Next
        
    With Application
        .FindFormat.Clear
        .ReplaceFormat.Clear
    End With
    VBA Noob

  5. #5
    Registered User
    Join Date
    10-21-2008
    Location
    Mumbai
    Posts
    3
    I am extremly thankful to VBA Noob and Stephen.......all the three solutions are quite good and impressive.

    Is it possible that by running macro once I can change the color in all the sheet of the workook.....if not than I have to run this 500 times.......

    Well, all this is after affect of Lehman Bankruptcy ..u know its color was GREEN
    Last edited by rishuverma; 10-21-2008 at 09:28 AM.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Both my methods worked for whole workbook

    VBA Noob

  7. #7
    Registered User
    Join Date
    10-21-2008
    Location
    Mumbai
    Posts
    3
    Thanks a ton guys for the help.......

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. reading data from merged cells in excel using a macro
    By varmabjr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2007, 12:07 PM
  2. macro for merging cells.....
    By mikeow in forum Excel General
    Replies: 7
    Last Post: 01-29-2007, 04:21 AM
  3. Macro into locked cells
    By elude3xo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2006, 04:11 AM
  4. Macro that copies results from formula cells but not the formula itself???
    By jermsalerms in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2006, 11:40 AM
  5. Macro to hide columns based on contents of two cells
    By Korae13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2006, 12:40 AM

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