+ Reply to Thread
Results 1 to 13 of 13

Replace text in brackets with another cell's value

  1. #1
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Replace text in brackets with another cell's value

    Hi,

    I have many cells in my worksheet that have text in brackets like this: "some text here [text in brackets to be changed] some additional text here".

    I want to create a macro that replaces all text within brackets in my worksheet with the text value in cell C5.

    Can someone please tell me how to do this?

  2. #2
    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 text in brackets with another cell's value

    Hi,

    One way - with your text in A1

    Formula: copy to clipboard
    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.

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

    Re: Replace text in brackets with another cell's value

    vba
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Re: Replace text in brackets with another cell's value

    Thanks for your replies!

    I tried jindon's vba and it worked

    Just one issue: when the macro runs it changes the formatting of the text and brackets.

    Ideally I would like to keep the text within the brackets in italics and keep the font colour of the brackets themselves white.

    Is there any way to do this e.g. through using a new macro or editing the current one?

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

    Re: Replace text in brackets with another cell's value

    Try
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Re: Replace text in brackets with another cell's value

    This worked for most of them, however I found some cells that begin with a bracket like this : "[text in brackets] additional text."

    The font of all of the text in these cells was turned white, instead of just the brackets.

    Any way to fix this?

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

    Re: Replace text in brackets with another cell's value

    Can't replicate it here, so upload a workbook...

  8. #8
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Re: Replace text in brackets with another cell's value

    sample excel file.xlsm

    Please see attached workbook

    The error only occurs if you type something in cell C5 more than once.

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

    Re: Replace text in brackets with another cell's value

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

  10. #10
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Re: Replace text in brackets with another cell's value

    I put it in but I still got the same error.

    I have a vba code that runs the macro every time cell C5 is changed if that is any help.

    Would it work if I had a seperate macro to change the text in the brackets, a seperate macro to change the brackets to white, and a seperate macro to change the text to italics?

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

    Re: Replace text in brackets with another cell's value

    Try this one
    Please Login or Register  to view this content.
    Due to the font color is determined by the first character of the cell, when Replace method runs, it apply to the cell color to replaced cell.

  12. #12
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Re: Replace text in brackets with another cell's value

    Thank you! this worked perfectly

    I will add to your reputation and mark the thread as solved

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

    Re: Replace text in brackets with another cell's value

    You are welcome and thanks for the rep.

+ 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. Replace text string in a cell and retain rich text formatting (Excel 2013)
    By CharlieBear in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-15-2015, 04:39 PM
  2. Replies: 13
    Last Post: 08-28-2014, 08:00 PM
  3. [SOLVED] Find text between brackets in a cell
    By jwillis07 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-06-2014, 06:03 AM
  4. Replies: 3
    Last Post: 02-14-2014, 08:08 AM
  5. need to add [brackets] to numbers in a cell that contain text and numebrs
    By steve21 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-21-2013, 02:30 PM
  6. Replies: 5
    Last Post: 04-19-2012, 09:02 AM
  7. [SOLVED] Custom format a text cell with square brackets: [ ] ?
    By StargateFan in forum Excel General
    Replies: 2
    Last Post: 02-06-2005, 12:06 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