+ Reply to Thread
Results 1 to 12 of 12

Macro needed to change cell color that only works if cell in range is selected first

  1. #1
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Macro needed to change cell color that only works if cell in range is selected first

    Help with this macro would be much appreciated.
    Select a cell within the range C2:D2000 and run a macro that colors the corresponding cell in column A.

    For example: Select one cell C4 or D4 and run the macro, this would color cell A4 but if the selection was outside of the range C2:D2000, a msg box would open.
    Last edited by Mayweed; 08-31-2010 at 01:30 PM.

  2. #2
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    My effort:

    Please Login or Register  to view this content.

    Right click on the worksheet tab and select View Code. Pop the above on the code page that appears.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    Wow, that was fast, thank you both,
    Please accept my apologies for the bad description but I wanted the macro to run from a button, only if a cell in the range was selected.
    The message box would appear only if the selected cell was out of range before hitting the button.

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    Should it run if more than one cell is selected?

    Dom

  6. #6
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    That would be great if possible,
    Example: Select C2 & D7, click the button and A2 & A7 would color fill.

    Now you've got me thinking, would it be possible to select the already color denoted rows and remove the color using the same button.
    Example: C2 & D7 are colored so select them again and hit the same button, this would remove the colour.
    Last edited by Mayweed; 08-31-2010 at 11:40 AM.

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    Try this:

    Please Login or Register  to view this content.

    Dom
    Last edited by Domski; 08-31-2010 at 12:09 PM.

  8. #8
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    Brilliant, Just a couple of problems I am trying to sort out.
    I thought that this would be easy enough for me to do but.... the color should change form white to RGB all 234 (light gray).
    When the colour is gray the cell should display the word 'Favorite'.

    I understand if this is pushing my original question too much, I thought that modifying your code would be easier than I'm finding it now.

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    Try:

    Please Login or Register  to view this content.

    Dom

  10. #10
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    Brilliant Domski, it works perfectly... Thank you very much indeed.
    If you dont mind me asking just one last question, how can I find out what the color index of an Excel fill is? I can only find RGB values.

  11. #11
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Macro needed to change cell color that only works if cell in range is selected fi


  12. #12
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Re: Macro needed to change cell color that only works if cell in range is selected fi

    I can't thank you all enough; this has saved me like.... probably years of learning.

+ 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