+ Reply to Thread
Results 1 to 12 of 12

how to look for spaces?

  1. #1
    Registered User
    Join Date
    09-17-2009
    Location
    Dendermonde - Belgium
    MS-Off Ver
    Excel 2003
    Posts
    4

    how to look for spaces?

    Hello

    I am creating a small function that should create a new login for future users. The login is 7 characters long. Spaces in that name (in cell A1 eg) should be removed? But how do I do this?
    How do I remove the space in the name: "De Castro Imelda". Apparently the function TRIM does not help me much. Either I use the wrong function, or I my syntax is not good...

    Many thanks for your advice.
    Last edited by verhaba; 09-17-2009 at 03:18 PM.

  2. #2
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: how to look for spaces?

    use substitute function

    Please Login or Register  to view this content.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: how to look for spaces?

    TRIM() only removes unnecessary spaces. It would leave at least 1 between existing words.

    If A1 has the text string De Castro Imelda, that includes two spaces to remove. This formula will do that:
    =SUBSTITUTE(A1, " ", "")
    Or this to remove just one space:
    =SUBSTITUTE(A1, " ", "", 1)

    Now, if you only want to display 7 characters of that for your login, then perhaps:
    =LEFT(SUBSTITUTE(A1, " ", ""), 7)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    09-17-2009
    Location
    Dendermonde - Belgium
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: how to look for spaces?

    Hey Thx,
    That was rather quick. It works... but still... I have a question... Just image that I have a name with 2 spaces or even with more (think of a Spanish or Latino family name). I have an inbedded function like this:

    =SUBSTITUTE(SUBSTITUTE(B8;" ";;1);" ";;1)

    Unfortunately it only works for two spaces in the name... I wonder if you cannot let excel count how many spaces there are and remove them automatically. Or this more a case for Visual basic? Thx in advance

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: how to look for spaces?

    The first formula I gave will remove all the spaces.
    =SUBSTITUTE(A1, " ", "")

  6. #6
    Registered User
    Join Date
    09-17-2009
    Location
    Dendermonde - Belgium
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: how to look for spaces?

    Quote Originally Posted by JBeaucaire View Post
    TRIM() only removes unnecessary spaces. It would leave at least 1 between existing words.

    If A1 has the text string De Castro Imelda, that includes two spaces to remove. This formula will do that:
    =SUBSTITUTE(A1, " ", "")
    Or this to remove just one space:
    =SUBSTITUTE(A1, " ", "", 1)

    Now, if you only want to display 7 characters of that for your login, then perhaps:
    =LEFT(SUBSTITUTE(A1, " ", ""), 7)
    Hi,
    Well the login should be in total 7 characters. These 7 characters should be made of
    5 characters of the family name (from where the spaces are removed) and
    2 characters from the name.
    But if the family name is less then 5 characters (eg 3 characters) than the amount characters used for completing the login needs to be increased till the total amount of the characters of login has reached 7. In this case the amount of characters used on the name should be 4 in stead of 2, since the family name has only 3 characters... Hope you'll understand what I am saying... :-)

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: how to look for spaces?

    Nope. Simplest...provide 3-4 examples of text strings and the login you would think is correct based on those strings. That should make it clear.

  8. #8
    Registered User
    Join Date
    09-17-2009
    Location
    Dendermonde - Belgium
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: how to look for spaces?

    Quote Originally Posted by JBeaucaire View Post
    Nope. Simplest...provide 3-4 examples of text strings and the login you would think is correct based on those strings. That should make it clear.
    Hi again,
    these are a couple examples

    family name - name --> login

    Verhaegen - Bart --> verhaba
    Li - Wangsu --> Liwangs
    Van Gucht - Karel --> vanguka (spaces are left out)

    Hope that you see where I am getting at...

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: how to look for spaces?

    i see that but there is no consistancy
    Verhaegen - Bart --> verhaba 4 from first 3 from second =7
    that sort of makes sense but why not 3 from first 4 from second or 5 from first 2 from second?
    Li - Wangsu --> Liwangs all of first 5 from second =7
    well thats sort of forced itself but coluld be Lwangsu
    Van Gucht - Karel --> vanguka what determines how many you take from this one?? could just as easily be vangkar or vgukare
    edit re read your post with rules!!!!!!!!
    but how are they presented in cells i presume the - isnt there
    Last edited by martindwilson; 09-20-2009 at 05:13 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: how to look for spaces?

    So, as a logic thread, it goes:

    1) If 3 words, remove first space to leave 2 words
    2) If first word greater than or equal to 5 letters, take 5 characters from first word and 2 from last word to create login
    3) If first word less than 5 letters, take all of first word and as many from second word to make 7-letter login.

    Is that correct?

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: how to look for spaces?

    If your data is laid out the way you showed and my logic above is correct, then this will work:

    Please Login or Register  to view this content.
    The formula in C2 then copied down is:
    =IF(LEN(SUBSTITUTE(A2, " ", ""))>=5, LOWER(LEFT(SUBSTITUTE(A2, " ", ""), 5) & LEFT(B2, 2)), LOWER(LEFT(SUBSTITUTE(A2, " ", "") & B2, 7)))

  12. #12
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: how to look for spaces?

    i went with this but it will fail if say name is li wan
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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