+ Reply to Thread
Results 1 to 12 of 12

macro needed: change cell colour based on input in another column

  1. #1
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Question macro needed: change cell colour based on input in another column

    Hi Guys

    As the title suggests, I'm looking for a simple macro that will change the colour of the cell in column's O and P (row range 27:600) to "light yellow" if there is any data in the same row in column B. My brain isn't working today and I cant seem to make this work!

    Any help would be much appreciated!

  2. #2
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: macro needed: change cell colour based on input in another column

    Please Login or Register  to view this content.
    You will have to look up the RGB color you want for whatever color.
    Last edited by 111StepsAhead; 05-23-2012 at 08:44 AM. Reason: Changed last_Row range to "B" from "A".

  3. #3
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Re: macro needed: change cell colour based on input in another column

    Many thanks for the swift response... although this doesn't seem to do anything! Which was the same problem I had as well...

    Please Login or Register  to view this content.
    I cant see why this isnt working, its driving me bonkers!!

    Also, to complicate things... Im looking at amend the macro to remove the cell colour (default back to white) if any text is entered into the cells in columns O and P. Is this feasible?

  4. #4
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: macro needed: change cell colour based on input in another column

    weesteev,

    You don´t need a macro to do this, just use conditional formating.

  5. #5
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: macro needed: change cell colour based on input in another column

    Last row is based on data in column A. You got data in that one?

  6. #6
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Re: macro needed: change cell colour based on input in another column

    Quote Originally Posted by rkey View Post
    Last row is based on data in column A. You got data in that one?
    Have changed to B (where the data is located) and still not working

    Quote Originally Posted by Pulsus View Post
    weesteev,

    You don´t need a macro to do this, just use conditional formating.
    Conditional formatting will only work in the targeted cell, I'm looking to adjust the colour of 2 cells based on the value in a different cell.

  7. #7
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: macro needed: change cell colour based on input in another column

    Where are you putting the code? It needs to go in a module. Not the particular worksheet. I just ran the code on a test workbook here and it worked fine.

  8. #8
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Re: macro needed: change cell colour based on input in another column

    Ok I have sussed out the problem! the code does indeed work but you need to manually run the macro. What im looking for is a VB script that will automatically run and detect input in column B, basically performing the function of conditional formatting. Any ideas?

  9. #9
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: macro needed: change cell colour based on input in another column

    Automatically is a bit harder. You can't just hotkey the macro?

    http://kb.iu.edu/data/ahbm.html

  10. #10
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: macro needed: change cell colour based on input in another column

    Please Login or Register  to view this content.
    Add the above code to the particular worksheet you want it to run on. Keep the other macro where it is.
    Last edited by 111StepsAhead; 05-23-2012 at 11:01 AM. Reason: Took out conditional so it works better.

  11. #11
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: macro needed: change cell colour based on input in another column

    weesteev,

    Select the cell O27.

    On conditional formating select "NEW RULE", then select the last option (Use a formula to ...), and insert this formula:

    =IF(B27<>"";1;0)

    After this Click in the "FORMAT BUTTON" behind and select the color you want.

    Repeat the same process on cell P27.

    So just use the format brush to all the cells you need that Rule.

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: macro needed: change cell colour based on input in another column

    Quote Originally Posted by Pulsus View Post
    weesteev,

    You don´t need a macro to do this, just use conditional formating.
    You've ignored the obvious answer!!!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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