+ Reply to Thread
Results 1 to 13 of 13

Macro to change text colour of adjacent cell to the same text colour as target cell

  1. #1
    Registered User
    Join Date
    06-07-2012
    Location
    SG
    MS-Off Ver
    Excel 2007
    Posts
    37

    Macro to change text colour of adjacent cell to the same text colour as target cell

    Hello,

    Is it possible to have a macro to have the text colour of a range of cells a particluar no. of columns to be the same text colour as their adjacent target cells?

    E.g.
    Column A = target cells
    Column D, E & F = adjacent cells for text colour to be changed

    If text colour of a cell in column A is white (cell A3), change the adjacent cells of column D, E & F (cell D3, E3 & F3) to be white text too. If the text colour of a cell in column A is black (cell A2), change the cells of column D, E & F (cell D2, E2, & F2) to be black text too.

    Anyway, I wanted a macro instead of other methods (if available) because this is code will be combined into my final macro for the final database.
    I've a sample data attached. Please advise. Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Hi
    The change of font color will not trigger event in VBA but You can use such code and after selection of cell in column A the rest of cells will change the color
    Please Login or Register  to view this content.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Registered User
    Join Date
    06-07-2012
    Location
    SG
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Hmm, I can't get the macro to work at all. Nothing changes.

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Hi,

    Try this

    Please Login or Register  to view this content.
    Please take time to read the forum rules

  5. #5
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Look into attachment and select any cell in column A
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-07-2012
    Location
    SG
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Your macro works but only for cell A2 & A3. Actually my database has a varying no. of data in it and will expand as I add more data. So I would need the macro to be able to be applied to a huge no. of data.

  7. #7
    Registered User
    Join Date
    06-07-2012
    Location
    SG
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Where did you put your macro into? I tried copy and paste into a new macro but doesn't work.

  8. #8
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Where did you put your macro into?
    If this question is for me then answer is: in the module of worksheet (click right button of mouse on the name of worksheet and choose view code - my code should be there)

  9. #9
    Registered User
    Join Date
    06-07-2012
    Location
    SG
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Hmm, I know where to insert Tom's code already. But this code doesn't give auto change of colour of text (which would be very tedious because I've hundreds rows of data to change manually) and itself changes whole row of text colour (which I only want particular columns).

    Steffen's code works better for me but I need it to be applied to a lot of data so is there a way to modify the code and make it run for hundreds of row of data?

    By the way, my data is only either in white or black text.

  10. #10
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    try this then
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-07-2012
    Location
    SG
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Great job! =)

    But can modify it further to only change colour of text in columns D, E & F only? Column B & C I still want it to be in black font. tyvm

  12. #12
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-07-2012
    Location
    SG
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Macro to change text colour of adjacent cell to the same text colour as target cell

    Oh yes this is the 1!!!! you're a genius!!! <3

+ 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