+ Reply to Thread
Results 1 to 6 of 6

Need to Concatenate & if/replace a string of characters

  1. #1
    Registered User
    Join Date
    02-27-2013
    Location
    AZ, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question Need to Concatenate & if/replace a string of characters

    So essentially I am creating a Unique ID that combines first and third letters of first name, first and third letters of last name, MM, DD, YY, and gender. (This was not my idea). All together it draws characters from 4 cells. Like this:

    # A B C D E
    1 first name last name date of birth gender unique ID
    2 Bo Smith 10301972 M BSI103072M
    3 Linda Brock 09011955 LNBO090155

    So the UID in cell E2 would be the result if I used "&" and "MID" to concatenate like this:
    =MID(A2,1,1)&MID(A2,3,1)&MID(B2,1,1)&MID(B2,3,1)&MID(C2,1,2)&MID(C2,3,2)&MID(C2,7,2)&D2

    The problem is that I have to replace all blanks "" with a 9. So I would want the UIDs to read B9SI103072M and LNBO090159. However, my formula simply leaves out blanks.

    I thought I could use the IF function to check/replace like so: =IF(MID(A2,3,1)="",9)

    However I couldn't figure out how to get the formula to "put" the character, and "if/then" it at the same time. Much less do this for the whole string.

    I tried: =MID(A2,1,1)IF(MID(A2,1,1)="",9)&MID(A2,3,1)IF(MID(A2,3,1)="",9)&.... but that didn't work.

    Any ideas?
    Last edited by DrQuickbeam; 02-27-2013 at 04:51 PM.

  2. #2
    Registered User
    Join Date
    02-26-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007 & Excel 2010
    Posts
    7

    Re: Need to Concatenate & if/replace a string of characters

    Hi there,

    Formula assumes the following layout of spreadsheet:

    A2 = first name
    B2 = last name
    C2 = date of birth
    D2 = gender

    "=MID(A2,1,1)&IF(LEN(A2)<3,"9",MID(A2,3,1))&MID(B2,1,1)&IF(LEN(B2)<3,"9",MID(B2,3,1))&MID(C2,1,2)&MID(C2,3,2)&RIGHT(C2,2)&D2"

    Broken down by components:

    first name: "MID(A2,1,1)&IF(LEN(A2)<3,"9",MID(A2,3,1))"
    last name: "MID(B2,1,1)&IF(LEN(B2)<3,"9",MID(B2,3,1))"
    date of birth: "MID(C2,1,2)&MID(C2,3,2)&RIGHT(C2,2)"

    Regards
    Johan

  3. #3
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Need to Concatenate & if/replace a string of characters

    Try

    =MID(A2,1,1)&MID(A2&REPT("9",3),3,1)&MID(B2,1,1)&MID(B2,3,1)&MID(C2,1,2)&MID(C2,3,2)&MID(C2,7,2)&D2
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  4. #4
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Need to Concatenate & if/replace a string of characters

    Copy and Paste into cell E3 and either copy and paste further down into cells you would also like converted.

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor Dunc3142's Avatar
    Join Date
    09-05-2007
    Location
    Franklin OH
    MS-Off Ver
    2000 and 2007 and 2010 @ Home & Teach 2010
    Posts
    351

    Re: Need to Concatenate & if/replace a string of characters

    Everyone forgot that middle Initial not present had to be replaced with a 9.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Dunc3142; 02-27-2013 at 05:14 PM.
    Yes it will. we just have to figure out how...
    If I have helped you, PLEASE click the * and add to my Rep.
    Also, if the problem is SOLVED please mark it as so.

  6. #6
    Registered User
    Join Date
    02-27-2013
    Location
    AZ, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Need to Concatenate & if/replace a string of characters

    Thank you for all your replies! I got it to work using the LEN function as presented by Johan and Dunc.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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