+ Reply to Thread
Results 1 to 8 of 8

Remove the first character only if it is a comma

  1. #1
    Registered User
    Join Date
    03-24-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    17

    Remove the first character only if it is a comma

    Hi all

    I have the following data in a column:

    E1, E14, E28, E29
    , E11
    , E15, E30

    I need to remove the first comma so that the data shows the following:
    E1, E14, E28, E29
    E11
    E15, E30

    I have tried using formula like =SUBSTITUTE(CO12,",",,1) and =REPLACE(CO8,1,1,"") but it doesn't work as it will remove the first comma in every cell such that my data becomes like this:
    E1 E14, E28, E29
    E11
    E15, E30

    I.e. the first cell removes the first comma and the 2nd and 3rd cell has a spacing in front.

    Any one can help?

    =============

    Actually, the above data comes from this formula:
    =IF($D5=$CE5,$D$3,"")&IF($F5=$CE5,", "&$F$3,"")&IF($H5=$CE5,", "&$H$3,"")

    any idea if it helps to improve this formula at all??
    Last edited by Pearlyn; 03-24-2013 at 10:57 AM.

  2. #2
    Valued Forum Contributor Harribone's Avatar
    Join Date
    02-24-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2019/365
    Posts
    570

    Re: Remove the first character only if it is a comma

    =if(left(a1,1)=",",trim(right(a1,len(a1)-1)),a1)
    Last edited by Harribone; 03-24-2013 at 11:03 AM. Reason: missing bracket
    Say thanks, click *

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Remove the first character only if it is a comma

    This works on the posted samples:

    =IF(LEFT(A2)=",",TRIM(MID(A2,2,100)),A2)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,298

    Re: Remove the first character only if it is a comma

    Or without 'trim'
    Please Login or Register  to view this content.
    Willem
    English is not my native language sorry for errors
    Please correct me if I'm completely wrong

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Remove the first character only if it is a comma

    As request:
    Quote Originally Posted by Pearlyn View Post
    Actually, the above data comes from this formula:
    =IF($D5=$CE5,$D$3,"")&IF($F5=$CE5,", "&$F$3,"")&IF($H5=$CE5,", "&$H$3,"")
    any idea if it helps to improve this formula at all??
    I think this formula need to be improved to remove comma "," at the beginning, not to place another formula in other cell.
    Donot testing, but try:
    Please Login or Register  to view this content.
    Quang PT

  6. #6
    Registered User
    Join Date
    03-24-2013
    Location
    Lahore, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    20

    Maybe try changing your original formula

    Try this:
    =IF($D5=$CE5,$D$3,"")&IF($F5=$CE5,"&$F$3","")&IF($H5=$CE5,"&$H$3","")

  7. #7
    Registered User
    Join Date
    03-24-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Remove the first character only if it is a comma

    Thanks all for your help. I have tried Tony's formula and it works.

    I tried correcting the original formula with Daedalus suggestion but it shows up the result as &E3. Also, for bebo formula, it may not be feasible as I have 39 IFs to build in

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Remove the first character only if it is a comma

    You're welcome. Thanks for the feedback!

+ 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