+ Reply to Thread
Results 1 to 7 of 7

Replace specific chars in string w/o changing existing font colour

  1. #1
    Registered User
    Join Date
    12-07-2012
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    81

    Replace specific chars in string w/o changing existing font colour

    I need to be able to go through a string and replace various items (not always the same ones).

    Most of the time the string is likely to have text of more than one colour, which I must not change.

    It would only ever be one char at a time that would need to be replaced.

    In the case I have before me, every instance of "{" needs to be replaced with "[".

    Likewise, every instance of "}" needs to be replaced with "]" , all without disturbing whatever colour the original chars had.

    So that I don't keep pestering people here, is there any way of generalising this so I can just alter the "find" and "replace with" items accordingly.

    In other words, I suppose I'm after a char by char version of the normal Replace function, that doesn't change formatting.

    As always, help much appreciated.

    Staggers.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Replace specific chars in string w/o changing existing font colour

    You can enter the required find/replace text in the 2 array lines.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    12-07-2012
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    81

    Re: Replace specific chars in string w/o changing existing font colour

    Wow, that's going straight in the toolkit. Only thing that's gone right so far today.

    Thanks very much Andy.

    Regards,

    Staggers

  4. #4
    Registered User
    Join Date
    12-07-2012
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    81

    Re: Replace specific chars in string w/o changing existing font colour

    Oh dear, it seems my delight was a little premature!

    Although it doesn't seem to matter (I've been experimenting) it's a merged cell that contains the strings being checked and altered where necessary.

    The problem seems to be with string length. These strings can be very long (up to 600 characters or more) and it seems that, regardless of where the items to be changed are in the string, once the total string length approaches about 300 characters or so it dies, and just leaves the string unchanged (which is a blessing, I suppose).

    I'm completely baffled as to what could cause this. I don't know if you have any ideas?

    Regards,


    Staggers.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Replace specific chars in string w/o changing existing font colour

    Looks like 255 limit is stopping it from working.

  6. #6
    Registered User
    Join Date
    12-07-2012
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    81

    Re: Replace specific chars in string w/o changing existing font colour

    That's what I thought, but because it wasn't 255 exactly I assumed it must be something else. Looks like I'm going to have to break it down into smaller bits first. That'll be fun, moving things around without messing up the formatting.

  7. #7
    Registered User
    Join Date
    12-07-2012
    Location
    London, England
    MS-Off Ver
    Office 2010
    Posts
    81

    Re: Replace specific chars in string w/o changing existing font colour

    And just to add inult to injury, Excel went insane and I couldn't make any buttons work, so I eventaully re-installed Office, and then it was even worse, with everything on all ribbons greyed-out, as if a cell somewhere was in edit mode, which it wasn't.

    Then I remembered that I had a 250MB MS update today. So I restored the system back to before the update and it all worked again. Thanks MS.

    I still have the above problem, but at least i can work on it now!

+ 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] Changing default font in existing workbook
    By Aussie1 in forum Excel General
    Replies: 5
    Last Post: 07-01-2020, 08:13 AM
  2. Getting Colour wise totals by changing font colour
    By Anuru in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-24-2014, 11:13 AM
  3. [SOLVED] Changing Font colour via formula
    By coach.32 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-07-2013, 06:52 PM
  4. Replies: 7
    Last Post: 04-09-2012, 04:27 PM
  5. Changing font colour
    By Peter Rump in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-28-2006, 01:08 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