+ Reply to Thread
Results 1 to 23 of 23

Macro that will turn any text (bracketed) to red

  1. #1
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Macro that will turn any text (bracketed) to red

    Hello All,

    I created two condition formats for the range of G1017:G4007 to turn certain text red.

    First Condition format, if cell contains text "No EN Worker Category", works so no need to change this unless the macro will effect this.

    The second Condition format is what I would like to be replaced with a macro. I want any text in (bracketed) to turn red and only the text in (brackets).

    Attached excel sheet for your reference. EN BG Report (Master) v2.2.3.xlsm

    In column M, I made a example of what the macro should do. In row 1037 and 1051 only the (bracketed) is red while the rest remains black.

    Hope this was clear.

    Thanks,

    Jason

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,719

    Re: Macro that will turn any text (bracketed) to red

    Add this code to the Sheet module for Sheet1 (Group Leader Summary). I have tested this.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by 6StringJazzer View Post
    Add this code to the Sheet module for Sheet1 (Group Leader Summary). I have tested this.

    Please Login or Register  to view this content.
    Thanks Jeff,

    I pasted this into a module... but how do i run this? I don't see it in the list of macro's to run.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,719

    Re: Macro that will turn any text (bracketed) to red

    You can't just paste it into a module, you must paste it into the module for the sheet containing this data.

    It will run automatically any time a cell on that sheet is changed.

  5. #5
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by 6StringJazzer View Post
    You can't just paste it into a module, you must paste it into the module for the sheet containing this data.

    It will run automatically any time a cell on that sheet is changed.
    Thanks 6StringJazzer,

    I pasted it into the sheet and seemed to work but it doesn't as I only want the (bracketed) text to turn red. Also there were some anomalies...

    Example: "HWWL (PMSS) SAW" would remain all black, but I want the "PMSS" to turn red.
    Example: "(PMSS) SC-HW" would turn all red, but I want the "SC-HW" to remain black.

    Thanks,

  6. #6
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Hi Jason
    The worksheet change code below will do what you want for the range in Column M on your example. It will change the text colour to red from the first "(" in a cell to the last ")" in a cell. I don't know if you want to restrict it to a range or do the whole sheet. Copy & paste it into the sheet module to test.

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Here is some code that will loop through column M & colour the cell text as desired. Put it in a normal module & call the macro from a button.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by Philb1 View Post
    Here is some code that will loop through column M & colour the cell text as desired. Put it in a normal module & call the macro from a button.

    Please Login or Register  to view this content.
    Thanks Philb1,

    Two options... nice.

    I tried the Macro one and works... but I noticed a couple anomalies...

    for "(OER) (SC-C) (SC-HW)" , the "(OER) (SC-C)" would be red and the (SC-HW) is still black.
    for "HWWL (PMSS) SAW" , the "(PMSS) SAW" would be red; not sure why it didn't see the end bracket?

    I also noticed this turns the whole line red if it is a reference from another location. ie; ='Sheer1'!A1 as opposed to the text typed out as "xxx (xxx) xxx". This isn't a big issue but be nice to be able to use on a reference.
    Last edited by JasonNeedsHelp; 11-20-2015 at 06:48 PM.

  9. #9
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Macro that will turn any text (bracketed) to red

    I know that you have the answers already, but just as an addiction, you could also use CONDITIONAL FORMATTING for this. Works fast and easy to do.
    If you are interested let me know

  10. #10
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by amartinez988 View Post
    I know that you have the answers already, but just as an addiction, you could also use CONDITIONAL FORMATTING for this. Works fast and easy to do.
    If you are interested let me know
    Hi amartinez,

    Yes, I know. But the challenge is that I only want part of the text to be red not the whole cell. Condition Format effects the whole cell.

  11. #11
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Macro that will turn any text (bracketed) to red

    Got you!

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Macro that will turn any text (bracketed) to red

    Integrate this part of the code and it will work

    Please Login or Register  to view this content.
    Place the module the worksheet, select a cell in your column M and then run this macro
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Macro that will turn any text (bracketed) to red

    Modified Sub RedText for it to work, tested it and it works:

    Please Login or Register  to view this content.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Macro that will turn any text (bracketed) to red

    1) You need to delete 1st conditional format otherwise it overrides changes by macro.
    2) You can either call "test" macro my selecting "test" via Alt + F8 or just change the cell(s).

    To a sheet code module
    Please Login or Register  to view this content.
    To a Standard code module
    Please Login or Register  to view this content.
    See attached.
    Attached Files Attached Files
    Last edited by jindon; 11-20-2015 at 07:23 PM. Reason: Fixed typo

  15. #15
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    This will find the last ")" & colour all the text in between the first "(" & the last ")" red

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

  16. #16
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Shorter versions below.
    I've been thinking of doing something like this to one of my journal books & until now, have been to lazy lol. Killed 2 birds with 1 stone

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

  17. #17
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,604

    Re: Macro that will turn any text (bracketed) to red

    Please Login or Register  to view this content.
    Ben Van Johnson

  18. #18
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro that will turn any text (bracketed) to red

    Nice code ProtonLeah.
    I thought about doing what you've done but I didn't know how to do it. I've worked out how your code works & now I do.
    Thanks
    Phil

  19. #19
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,604

    Re: Macro that will turn any text (bracketed) to red

    Philb1,
    Thank you

  20. #20
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Macro that will turn any text (bracketed) to red

    Anybody take a look at this at all?

    Please Login or Register  to view this content.
    There are more than one ocurrences (...) (...)
    This works

  21. #21
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Thanks All!

    I tried all of these and they all seem to work. Now i just need to decide which one...

    Thanks again!

  22. #22
    Forum Contributor
    Join Date
    10-15-2013
    Location
    Calgary, Alberta
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Macro that will turn any text (bracketed) to red

    Quote Originally Posted by protonLeah View Post
    Please Login or Register  to view this content.
    Not sure why.. but recieved a debug on

    ReDim LeftRightPos(1 To StrLen, 1 To 2)

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Macro that will turn any text (bracketed) to red

    Perhaps easiest to understand.
    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)

Similar Threads

  1. Sum multiple bracketed values in the same cell
    By dobraf in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 04-03-2014, 07:01 PM
  2. Insert a blank row before bracketed text
    By bvlahides in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-04-2013, 08:19 PM
  3. Create 1 by 2 bracketed matrix in Excel
    By Coukapecker in forum Excel General
    Replies: 0
    Last Post: 09-28-2011, 01:02 PM
  4. Loop all cells to remove bracketed text
    By gcoug in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-29-2011, 04:38 PM
  5. Replies: 3
    Last Post: 06-02-2011, 11:03 AM
  6. Replies: 3
    Last Post: 08-23-2005, 05:05 PM
  7. [SOLVED] BRACKETED NEGATIVE NUMBERS IN EXCEL
    By Bushco in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-11-2005, 10:06 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