+ Reply to Thread
Results 1 to 4 of 4

Repeat characters after certain character

  1. #1
    Registered User
    Join Date
    01-13-2016
    Location
    New York, United States
    MS-Off Ver
    Windows 7
    Posts
    8

    Repeat characters after certain character

    I am looking to add "0" to the beginning of a number until there is a maximum of four digits. For example, 1 -> 0001, 40 ->0040, 623 ->0623. The current formula I have is as follows

    Assuming I am looking in cell A1, I have

    =IF(LEN(TRIM(A1))<4,REPT("0",4-LEN(TRIM(A1)))&A1,A1)

    I have a cell that is "MK-20". How do I modify the formula to have the result be "MK-0020"? Essentially, I would like to apply the the formula after the "-". I know I parse out the data and work from there but I'd like to try to avoid that.

    - James

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: Repeat characters after certain character

    Maybe something like this?

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

    If you feel someone has helped you please thank them and click on the star on their post to add reputation.
    Please ensure that you use code tags where relevant, and mark solved threads as solved.
    Most of all please be respectful and understanding of others.

  3. #3
    Registered User
    Join Date
    01-13-2016
    Location
    New York, United States
    MS-Off Ver
    Windows 7
    Posts
    8

    Re: Repeat characters after certain character

    Stephen,

    This works perfectly. Thanks man

    - James

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: Repeat characters after certain character

    What is your exact starting point for this? A number or another text string?

    If I assume you are starting from a number/integer, I might first suggest simple number formatting to get this (number format codes and description: https://support.office.com/en-us/art...2-09fab54be7f4 ). If you have a number (0-9999) in a cell, a number format code like "MK-"0000 will display that number the way you describe. So the number 12 would look like MK-0012. The cell will display MK-0012, but it is important (and maybe useful) to recognize that the underlying cell value is still 12. One could have =A1+1 in the cell underneath to get MK-0013, for example.

    Assuming, again, that you are starting with a number, and you want more than just the display changed -- you want the exact text string returned. You can use the TEXT() function (https://support.office.com/en-us/art...8-93d29371225c ) with the same number format code to convert the number 12 to the text string "MK-0012".

    If you are not starting with a number, then I would suggest a better description of what you are starting with.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. Removing Characters from Right Until Certain Character
    By jam_ran in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-13-2016, 12:19 PM
  2. Repeat Characters Appearing in a Text Box
    By archerweps in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-10-2014, 06:51 PM
  3. [SOLVED] How to replace all characters before a specific character
    By allsystems in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-08-2013, 08:40 AM
  4. Finding first character in a row of characters
    By barneyrubble1965 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-27-2013, 10:45 AM
  5. Replies: 3
    Last Post: 11-08-2012, 05:01 PM
  6. Change Character color after 55 characters
    By geeben in forum Excel General
    Replies: 1
    Last Post: 04-20-2010, 12:17 AM
  7. [SOLVED] Repeat characters to cell width
    By David in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-10-2005, 09:06 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