+ Reply to Thread
Results 1 to 4 of 4

Replace substrings but keep constant overall string length

  1. #1
    Registered User
    Join Date
    04-18-2017
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    6

    Replace substrings but keep constant overall string length

    I need a formula to replace a character that may or may not repeat itself in a string. I've read through enough threads about FIND/SUBSTITUTE to think there's a way to do it, but none of them help me keep the overall string length the same.

    Example - let's say I want to replace the * in the string with # instead. ABCD*FGH becomes ABCD#FGH. I can handle that. But my source data has varying numbers of *, and string length must remain at 8 characters, and FGH will always be the last three characters - that's where I get stuck. ABCDFGH are variable, not always those specific characters.

    ABCD*FGH becomes ABCD#FGH
    ABC**FGH becomes ABC##FGH
    AB***FGH becomes AB###FGH
    A****FGH becomes A####FGH

    I know how to handle each separate scenario, but don't know how to nest the pieces in a way so one formula will address all those possible scenarios.

    Thank you for your help!

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Replace substrings but keep constant overall string length

    If I am understanding you correctly, this should do what you're looking for:

    =SUBSTITUTE(A1,"*","#")

  3. #3
    Registered User
    Join Date
    04-18-2017
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Replace substrings but keep constant overall string length

    Oh, my goodness, I feel silly. That worked.

    I had been under the belief that that would only fix the first instance of * and wouldn't help when multiple * appeared in the same string, so searched and tried multiple nested SUBSTITUTE and IF variations.

    Thank you.

  4. #4
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Replace substrings but keep constant overall string length

    You're welcome. That would have been the case only if you specified an instance number.

    =SUBSTITUTE(text, old_text, new_text, [instance_number])

+ 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. How to extract a substrings if length is not known
    By Dan Carlson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2014, 09:42 PM
  2. [SOLVED] VBA to Find Multiple Substrings Within a String
    By learning_vba in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-06-2014, 07:35 AM
  3. [SOLVED] VBA substrings in string
    By mikejclark in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-28-2013, 08:36 AM
  4. Excel 2007 : Finding substrings in a string
    By kkerr in forum Excel General
    Replies: 4
    Last Post: 06-19-2012, 11:57 AM
  5. Changing multiple substrings within a string
    By RogueArchon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2012, 12:57 PM
  6. Substrings from String
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-23-2010, 05:08 PM
  7. Separtaing A String Into Substrings.
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 07-10-2005, 01:27 AM

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