+ Reply to Thread
Results 1 to 9 of 9

Replace 'Bold' text with '(Bold)' text

  1. #1
    Registered User
    Join Date
    09-10-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    5

    Replace 'Bold' text with '(Bold)' text

    Hi,

    I'm looking to replace the bold words in a piece of text, with the same words but surrounded by brackets:

    From:
    This is an example sentance.

    To:

    This is an {example} sentance.
    Or:
    This is an {example} sentance.

    Any help would be much appreciated.

  2. #2
    Forum Expert avk's Avatar
    Join Date
    07-12-2007
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    3,223

    Re: Replace 'Bold' text with '(Bold)' text

    Try with if your data in "A2"
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    atul


    If my answer (or that of other members) has helped you, please say "Thanks" by clicking the Add Reputation button at the foot of one of their posts.

    Also: if your problem is solved, please take the time to mark your thread as SOLVED by going to the top of your first post, selecting "Thread Tools" and then "Mark thread as solved".

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Replace 'Bold' text with '(Bold)' text

    Hi,

    Here's a sheet double click event that will do what you ask.

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Replace 'Bold' text with '(Bold)' text

    This is a more "mechanical" approach:

    As in Richard Buttrey solution, the change is triggered by a double click on the cell containing the text

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  5. #5
    Registered User
    Join Date
    09-10-2016
    Location
    UK
    MS-Off Ver
    2007
    Posts
    5

    Re: Replace 'Bold' text with '(Bold)' text

    Many thanks all, these have the desired effect - however, I'm looking to do this as a batch operation, rather than manually. How would I go about converting several thousand lines of text in this way? Apologies for not specifying in my OP.

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Replace 'Bold' text with '(Bold)' text

    Oh dear!
    I would not recommend using my method with thousands of rows. You may experience two birthdays waiting for an answer!
    Last edited by kev_; 04-18-2017 at 11:29 PM.

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Replace 'Bold' text with '(Bold)' text

    Give this a try EDIT: after further thought - posts #8 & #9 probably yield a better solution for you
    - in testing it took approx. 4 seconds per 1000 cells
    - suggest you test it on 100 cells first
    - if you run it on full data set close all other applications
    - it checks every cell in allotted range
    - define your range as tightly as possible eg Range("A:Z") would take forever as VBA checks more than 26million cells
    - amend sheet and range details

    This line avoids empty cells and those containing formulas from being processed:
    Please Login or Register  to view this content.
    Place this in a General Module:
    Please Login or Register  to view this content.
    To reduce the number of cells being checked:

    If there are discrete blocks where the text is located, range could be defined with the UNION function:
    Please Login or Register  to view this content.
    Last edited by kev_; 04-19-2017 at 01:48 AM.

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Replace 'Bold' text with '(Bold)' text

    A late thought.
    This could probably be a better way to set your range (based on cells containing text only):

    Please Login or Register  to view this content.
    Test it standalone first with the message box to see what it yields


    IF condition can then be removed from the VBA and the code (to be placed in a general module) becomes:
    Please Login or Register  to view this content.
    Last edited by kev_; 04-19-2017 at 01:50 AM.

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Replace 'Bold' text with '(Bold)' text

    And combining this technique:
    Please Login or Register  to view this content.
    With the UNION function to give:
    Please Login or Register  to view this content.
    results in only cells containing constant text in those ranges being checked

    Apologies for the rather scrappy build up - I forgot all about the rather useful attribute xlTextValues
    Last edited by kev_; 04-19-2017 at 01:53 AM.

+ 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. [SOLVED] SUM if Bold UDF to Ignore Bold Formatted Text
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2015, 01:15 PM
  2. Replies: 1
    Last Post: 11-03-2014, 05:07 PM
  3. Replies: 6
    Last Post: 05-01-2014, 04:13 AM
  4. Align msgbox text and Bold & underline certain text
    By alexnkc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 11:01 PM
  5. Split cell - bold text and non bold text.
    By desertshift in forum Excel General
    Replies: 10
    Last Post: 11-21-2010, 08:13 PM
  6. Delete all text which is not 'bold' in cells with 'mingled bold' text
    By Excelfriend in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2010, 04:47 PM
  7. Join bold and non-bold text in one cell
    By bkincaid in forum Excel General
    Replies: 3
    Last Post: 03-20-2006, 09:10 PM

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