Bold part of text in a cell, based on contents of separate column

I have a large glossary which contains example sentences containing the glossary terms. I'm looking for a formula that will automatically bold the instance of the glossary term.


Sample of glossary below:


The glossary terms are listed in Column A, and example sentences in Column B. Ideally, a formula in Column C would generate the results I've included in C1.


Is there a conditional formatting formula, or standalone formula, that I can use to automatically generate this formatting?


TIA!

MacBook Pro 15″, macOS 13.4

Posted on Jun 2, 2023 12:25 PM

Reply
6 replies

Jun 2, 2023 11:43 PM in response to Barry

I attempted that but it then missed the term if it is at the beginning or ending of the sentence or if it has punctuation after it. REGEX I think solves that.


=TEXTBEFORE(C2,REGEX("\b("&B2&")\b",FALSE))&B2&TEXTAFTER(C2,REGEX("\b("&B2&")\b",FALSE))



Notice row 3 only highlights the first "cat" in the sentence. I'm still stumped on how to do more. It also removes the capitalization because the word being inserted is not capitalized.


An alternative solution that gets all occurrences and has no problem with capitalization is to capitalize each occurrence instead of using bold. SUBSTITUTE can do that easily.



C2 =SUBSTITUTE(B2,REGEX("\b"&A2&"\b",0),UPPER(A2))


Jun 2, 2023 4:19 PM in response to seradka

I have a way to do it if there is only one occurrence of the term in the sentence. It is probably possible to do additional occurrences but it might take a lot more work to do it. Is one enough?



Column B formula is =A

Format these cells as bold

Formula in D is =TEXTBEFORE(C,B)&B&TEXTAFTER(C,B)


You can do without column B if you bold column A instead and substitute A for the B's in the formula


It is unlikely that this will export to Excel and work the same way, if that matters.

Jun 2, 2023 10:13 PM in response to Badunit

Clever solution!


Regarding "I'll have to think about how to fix that."


This may do the fix:


Formula is the same as in Badunit's post. The only changes are to enter/type a space before and after cat in cell, B2, and to apply bold to that entry. If these changes were made to the entry in column A, there would be no need to repeat the entry in column B.


Regards,

Barry


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Bold part of text in a cell, based on contents of separate column

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.