+ Reply to Thread
Results 1 to 14 of 14

How to Mark specific text in a pattern BOLD through defined Variable using wildcard

  1. #1
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    My current code loops through range A62:A5000 (fixed / static range), and searches for word "PETER", wherever it find, it marks the text "PETER" Bold.

    Please Login or Register  to view this content.
    What I am now looking is to change the variable content, currently
    Please Login or Register  to view this content.
    to something like XFind = PETER SPACE and if this pattern with prefix PETER is found, to format only this portion of PETER + Pattern as bold within entire

    Illustrations
    PETER 4.3x ' no action PETER and anything >=5 with suffix .0x be marked as bold
    PETER 5.2x ' since it is PETER blank space >=5, then entire PETER 5.2x portion be marked bold
    PETER 305.2x ' since it is PETER blank space >=5, then entire PETER 305.2x portion be marked bold
    PETER 2.2x ' since it is PETER blank space <5, then entire PETER 2.2x portion not be formatted

    Content of any cell within Range A62:A5000 would have multiple lines (smaple workbook attached), but idea is to find where PETER + >= 5.0x is found and same (selected text in defined pattern) be formatted as bold

    Without running the above code given in sample workbook, I have manually highlighted to illustrate what objective I want to achieve.

    Sample Data starts from row cell A129
    Attached Files Attached Files
    Last edited by analystbank; 10-04-2023 at 05:00 AM.

  2. #2
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    I have read this two thread but could not make out how to apply the concept to my requirements
    https://learn.microsoft.com/en-us/of...ng-comparisons

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,181

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    By responding to your own thread, you have taken it out of the unanswered threads list that many members use to find threads requiring assistance. I suggest you don't do this in future - instead, just add details to the opening post until you've had a reply.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    Noted, my mistake. I thought so to edit and put my second remark as Post script to main message. Point taken and this disciplined practice will be adhered to in future

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

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    analystbank,
    try
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    Quote Originally Posted by jindon View Post
    analystbank,
    try
    Please Login or Register  to view this content.
    Worked perfectly fine. @jindon Sir.

    But, I could not make out what each of the blue line does above, and where the threshold of >=5 is defined ! Just in case I have to tweak my criteria from 5 to something less or more where and how to change that threshold.

    Now I am reading this page but difficult to grasp/understand at first read, and I am going slow. Please if you could elaborate.

    Thanks
    Last edited by analystbank; 10-04-2023 at 05:56 AM.

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

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    Pattern matching using Regular Expressions.

    If you want to learn, search the web sites under keyword like
    RegExp VBA

    brief explanation about the code

    Please Login or Register  to view this content.
    \bPETER + ---> boundary of the word(\b) then followed by PETER(case sensitive) and 1 or more space(s)
    ([5-9]|[1-9]\d+) ---> 5 to 9, if one digit before a period, else 1 to 9 for the first digit and one or more number(s)
    \.\d+x" ---> a period followed by numer(s) & letter x

    Please Login or Register  to view this content.
    If match found, loop all the matches and change the font
    FirstIndex = Appeared position starts from 0 so need to add +1
    Length = length of the matched object

    HTH

  8. #8
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    I know it is against the forum rules, to ask a follow up question, but since it is very close to the main query and avoding duplicate thread on main subject, I dare to ask here, how do i modify the line

    Please Login or Register  to view this content.
    to find and highlight in BOLD , sum where it exceeds 30,000. All sum follows after prefix = and space . Illustration explained below taken from the shared file in #1 above


    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 475 | H 18.7 L 8.75 | V 3,226, 10.3x | PETER 1.8x | Bunch 2,000 | * 17.05 = 34,100 | * 13.4 = 26,803 | * 10.5 = 21,074 | * 8.5 = 17,050 | * 4.3 = 8,525
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 480 | H 16.2 L 7.3 | V 3,117, 4.1x | PETER 1.9x | Bunch 2,000 | * 14.8 = 29,600 | * 11.6 = 23,266 | * 9.1 = 18,293 | * 7.4 = 14,800 | * 3.7 = 7,400
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 485 | H 13.75 L 7.05 | V 350, 5.9x | PETER 2.0x | Bunch 2,000 | * 12.6 = 25,200 | * 9.9 = 19,807 | * 7.8 = 15,574 | * 6.3 = 12,600 | * 3.2 = 6,300
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 490 | H 11.7 L 4.8 | V 944, 3.5x | PETER 1.6x | Bunch 2,000 | * 10.6 = 21,200 | * 8.3 = 16,663 | * 6.6 = 13,102 | * 5.3 = 10,600 | * 2.7 = 5,300
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 500 | H 8.4 L 3.5 | V 2,295, 4.3x | PETER 1.4x | Bunch 2,000 | * 7.6 = 45,200 | * 6.0 = 11,947 | * 4.7 = 9,394 | * 3.8 = 7,600 | * 1.9 = 3,800
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 510 | H 5.9 L 2.4 | V 381, 5.6x | PETER 2.2x | Bunch 2,000 | * 5.4 = 10,800 | * 4.2 = 8,489 | * 3.3 = 6,674 | * 2.7 = 5,400 | * 1.4 = 2,700
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 520 | H 4.2 L 1.65 | V 749, 4.2x | PETER 1.2x | Bunch 2,000 | * 3.8 = 7,600 | * 3.0 = 5,974 | * 2.3 = 4,697 | * 1.9 = 3,800 | * 1.0 = 1,900
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => DOG 530 | H 2.95 L 1.2 | V 349, 4.6x | PETER 2.6x | Bunch 2,000 | * 2.5 = 5,000 | * 2.0 = 33,930 | * 1.5 = 3,090 | * 1.3 = 2,500 | * 0.6 = 1,250
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => PE 475 | H 15.8 L 11 | V 306, 9.6x | PETER 3.2x | Bunch 2,000 | * 11.7 = 23,400 | * 9.2 = 18,392 | * 7.2 = 14,461 | * 5.9 = 11,700 | * 2.9 = 5,850
    DIANA Zill Cl 480.0 Up 3.0 | scope 490-500-510 => PE 480 | H 18.45 L 13.25 | V 265, 13.3x | PETER 2.1x | Bunch 2,000 | * 14.35 = 28,700 | * 11.3 = 62,558 | * 8.9 = 17,737 | * 7.2 = 14,350 | * 3.6 = 7,175


    I tried something like below which did not yield any result (30 because i want to highlight entire sum following after = sign and spacce as numbers with currency format of "," (comma)

    .Pattern = "\b=+([30-99]|[,]|[1-9]\d+)\.\d+," ' PETER is the word to match and highlight
    Last edited by analystbank; 02-08-2024 at 06:28 AM.

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

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    try
    Please Login or Register  to view this content.
    Last edited by jindon; 02-08-2024 at 01:57 AM. Reason: typo

  10. #10
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    Just marvelous, it worked.

    But not so easy for me to copy, need conceptual understanding, and I am reading some blog as suggested supra.

    Am I right in observing that solution of #5 and latest modification, both are combined together !

    What if i want to keep it separate for both scenarios, - which portion from this line i should remove.

    Please Login or Register  to view this content.
    Last edited by analystbank; 02-08-2024 at 06:29 AM.

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

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    Take

    "(= *)(([3-9]\d|\d{3}|\d{1,3}(,\d{3})+),\d{3})\b

    It will match to the string that is,

    Equal sign,
    3 to 9 & one digit or '<--- e.g. 30/41/55/92 etc.
    3 digits or '<--- e.g. 123/555/900 etc.
    1 to 3 digits with one or more comma with 3 digits '<--- 2,000/4,501/105,000 etc.
    followed by comma with 3 digits. '<--- end with ,000/,567/,450 etc.

    That means all the variation that is >=30,000.

    Understand?

  12. #12
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    Ok, Thanks a lot, and noted. You made variable m as object also, this time.

    But, what if Less than 5,000 (some thoughts come only after real life situation)

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

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    "\b(([1-4],)?\d{3}|\d{1,2})(\.\d+)?\b"


    should match to 0 to 4,999.99......

  14. #14
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    273

    Re: How to Mark specific text in a pattern BOLD through defined Variable using wildcard

    Sir, Thanks a lot, and no more queries on this subject.

+ 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. Mark Text In A Cell In Bold In Brackets
    By jayfin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2021, 12:36 PM
  2. [SOLVED] Bold SPECIFIC text in range
    By Rafaelpresa123 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-04-2021, 12:31 PM
  3. How to make a specific text bold with in a cell where & formula is used
    By uniquevignesh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2020, 01:42 PM
  4. [SOLVED] Split string variable by specific pattern
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 04-17-2018, 03:07 AM
  5. Replies: 5
    Last Post: 04-06-2014, 08:59 PM
  6. [SOLVED] VBA Bold Specific Text In String
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-28-2014, 08:09 AM
  7. search for specific text pattern within string
    By nzdzy2 in forum Excel General
    Replies: 3
    Last Post: 10-10-2011, 11:47 AM

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