+ Reply to Thread
Results 1 to 6 of 6

Replace consecutive underscores with a specified set of characters

  1. #1
    Registered User
    Join Date
    10-05-2017
    Location
    NJ
    MS-Off Ver
    2016
    Posts
    3

    Replace consecutive underscores with a specified set of characters

    Hello all,

    I have an excel sheet with data entered for a card game. I have a bunch of cells with a group of underscores, i.e. "He went to the _______." or "She also went to the __."

    I want to be able to replace these sets of underscores with another set that is a specific length. Like instead of 5 underscores here, and 3 there, and 6 there... I want to replace each group with exactly 8 underscores, "________".

    Is there an easy way to do this?

    Thank you

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,262

    Re: Replace consecutive underscores with a specified set of characters

    Try

    =A1& " "& B1

    A1=Text
    B1=8 underscores (________)

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Replace consecutive underscores with a specified set of characters

    This depends how the text and underscores are set on the sheet. Are the text and underscores in the same cell? Or is it text in a cell, underscores in a cell next to it?

    If they are separate find and replace is likely the quick and easy...if the underscores are alone in their own cell

    You may also be able to use find and replace. Something like:

    Find: *_*
    With: ________

    However if there is text and underscores mixed, then you will likely want to look at a formula to do it. The example given above would combine text without underscores with the desired number of underscores...it wont fix things for you if there is text and underscores mixed in a cell already.

    For that you may want to look at the SUBSTITUTE function. You may also combine something like LEFT/RIGHT/MID with FIND and CONCATENATE. Is the underscoring always at the end of a sentence?

    If its always at the end (assuming cell with text and underscore is in B3):

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If underscoring could be anywhere in the string:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Not the most elegant formula, but gets the job done. Essentially I replace the first underscore with a character I know wont be in any string, I picked "*" but you can change to your liking. I then replace the other underscores with nothing. Lastly I replace my special character, "*", with 8 underscores. This would not affect text before/after the underscores in your string, but would also only work if there is one set of underscores in the string.

    Ie: Works - "He went to the _____."
    Doesnt work - "He went to the _____ and to the _______."

    Hopefully this helps

  4. #4
    Registered User
    Join Date
    10-05-2017
    Location
    NJ
    MS-Off Ver
    2016
    Posts
    3

    Re: Replace consecutive underscores with a specified set of characters

    It worked! Thank you so much. There was only one or two that had double sets in the same cell. Any other double sets we actually in separate cells in the same row so it still worked. Thanks again!

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Replace consecutive underscores with a specified set of characters

    If you are satisfied with the results you may consider mentioning what specifically worked. At the very least mark the post solved.

  6. #6
    Registered User
    Join Date
    10-05-2017
    Location
    NJ
    MS-Off Ver
    2016
    Posts
    3

    Re: Replace consecutive underscores with a specified set of characters

    Quote Originally Posted by Zer0Cool View Post

    If underscoring could be anywhere in the string:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This was it, thanks.

+ 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] Replace accented characters in worksheet name to regular characters
    By kingsdime29x in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2017, 10:59 AM
  2. Replies: 9
    Last Post: 03-05-2016, 12:53 AM
  3. count of consecutive characters
    By AnushPatel in forum Excel General
    Replies: 6
    Last Post: 10-30-2014, 08:10 AM
  4. [SOLVED] find and replace to not replace characters found as wildcards
    By sabutler4 in forum Excel General
    Replies: 4
    Last Post: 07-03-2013, 06:48 PM
  5. Excel 2007 : Replacing 2+ consecutive characters
    By PennyKat in forum Excel General
    Replies: 6
    Last Post: 12-14-2011, 07:04 PM
  6. Name Ranges: Function to convert special characters underscores
    By Calanbraun in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-20-2006, 02:10 AM
  7. [SOLVED] How can I replace spaces in text cells (excel) with underscores?
    By JB2006 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-20-2006, 01: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