+ Reply to Thread
Results 1 to 9 of 9

Macro Based on Cell Background Color

  1. #1
    Registered User
    Join Date
    08-30-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Talking Macro Based on Cell Background Color

    Hi all,

    I'm looking to create a Macro that searches the defined ranges (Range1 to 75) in a sheet called "Layout" and if it has a red background then I want it to perform a Macro after users double click on the Range. The Macro will be to unhide rows on a second sheet called "Reports". I have a similar thread using checkboxes and a command button, but based on feedback from users; they'd prefer something different.

    What I have so far is:
    Please Login or Register  to view this content.
    I'm not sure how to incorporate the double click part and i'm still working on the background.color = red selection property.
    Attached Files Attached Files
    Last edited by Kinchen; 09-06-2011 at 03:46 PM. Reason: Problem was solved

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro Based on Border Color

    Difficult to test without real data but try something like this.

    Please Login or Register  to view this content.
    Paste into the appropriate sheet tab in the VBA editor.
    Martin

  3. #3
    Registered User
    Join Date
    08-30-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Macro Based on Border Color

    Sorry I meant to put range background color. Also, I've attached a mock spreadsheet that is the same as the one i'm working on.

    CK

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro Based on Cell Background Color

    Try this

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-30-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Macro Based on Cell Background Color

    Thanks for the quick reply I've tried adding the code and it's not wanting to work. I've tried adding into the page code as well as as a separate macro triggered by a command button. Perhaps it would be easier to do away with the double click aspect and just unhide cells when the backgound color of any cell within a named range is red ( I found that the color index # is 255 for the red red i've used).

  6. #6
    Registered User
    Join Date
    08-30-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Macro Based on Cell Background Color2

    This Post is a little different then my last as I have managed to get the macro to work based on background color i'm just having problems using variables within a range. The code I have so far is:

    Please Login or Register  to view this content.
    I have three rows of boxes so i'm going to repeat this formula three times and define more variables. I have had this code work with a defined range of:

    Please Login or Register  to view this content.
    but the problem i was having was that it would only unhide cells if the first cell in the first box had a red background regardless of if other boxes had red backgrounds. Any help is welcomed . I'd prefer not to use the double offset and have a formula for the row such as the one in the first CODE box.
    Last edited by Kinchen; 09-01-2011 at 01:50 PM.

  7. #7
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro Based on Cell Background Color

    The line

    Please Login or Register  to view this content.
    needs to be inside the loop otherwise the value of B does not change from its initial value of 0.

  8. #8
    Registered User
    Join Date
    08-30-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Macro Based on Cell Background Color2

    I'm am pretty new to VBA. How can I do this? Like this?
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-30-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Macro Based on Cell Background Color

    Quote Originally Posted by mrice View Post
    Try this

    Please Login or Register  to view this content.
    [QUOTE=mrice;2589950]

    Thank you for your help mrice. I finally got it to work. The code you gave me did a perfect job at recognizing whether the cell had a red background, but it only unhide 1 row instead of 35. The best part was it was the right row i just needed to modify your code to expand it to the 35. Here is what I did and it works flawlessly and it is fast too.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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