+ Reply to Thread
Results 1 to 17 of 17

Remove Leading zeros keeping hidden apostrophe as is

  1. #1
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Remove Leading zeros keeping hidden apostrophe as is

    Hi Guys,

    I have a column which contains some IDs. Now, most of these IDs are numeric barring few which are text. However, the formatting of all the cells is same which is General. I also see a hidden apostrophe at the begining of text or number in each of the cells of this column.

    I need to remove the leading zeros from the cells which contain number (there would always be 4 leading zeros which I need to remove) and leave aside the cells which have text. Also, the leading apostrophe (which is hidden in all the cells) should remain in tact.

    Ex -

    '0000123456
    '0000238983
    'Text
    'Free Text

    What I want is

    '123456
    '238983
    'Text
    'Free Text

    Please note that leading apostrophe appears only when I double click on the cell, else it is hidden.

    Any help please.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Assuming those are in column A starting in A1, put this formula in B1:

    =IF(ISNUMBER(A1*1),TEXT(A1*1,"0"),A1)

    then copy down. Then you can fix the values in column B and delete column A.

    Hope this helps.

    Pete

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Remove Leading zeros keeping hidden apostrophe as is

    I think unless you use find and replace (search for 0000 and replace with "") any formula based approach would get rid of the hidden '

    The problem with that approach is it would remove 0000 strings from any position.

    You could use a formula like = TEXT(--A1,"0") which would give you the number without leading 0's as a text string which is kind of the same thing, or you could use a vba solution like
    Please Login or Register  to view this content.
    which would maintain your apostrophe.

  4. #4
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Yes, with both the above solutions, it removes the zeros but doesn't keep the ' either. Not working.

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Use the vba option then.

  6. #6
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Any other solution that will keep the apostrophe as well. If you are suggesting a macro, please help me how to enable that macro.

    Regards,
    Ashish

  7. #7
    Forum Contributor mubashir aziz's Avatar
    Join Date
    03-18-2009
    Location
    Lahore, Pakistan
    MS-Off Ver
    MS Office 2013
    Posts
    533

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Have you tried by Pressing Ctrl+H and replace 0000 with nothing ?
    If this post helps, Please don't 4get to click the star icon located at the bottom left of my Post.

  8. #8
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Hi Mubashir,

    I can't do that as it is a 10 digit no. and can have '0000' somewhere in middle as well. Something like - '0000100001

    Regards,
    Ashish

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Remove Leading zeros keeping hidden apostrophe as is

    As suggested in posts 3 and 7 you could try using find and replace - this would maintain the apostrophe.

    If you need help implementing the macro please upload a workbook with an example of the layout of the data and I wil adjust the macro for you.

  10. #10
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Remove Leading zeros keeping hidden apostrophe as is

    ragulduy,

    Can you please let me know how can I apply that VBA to entire column. Where do I do that please?

    Regards,
    Ashish

  11. #11
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Hi - please upload the workbook showing an example of the data and I will complete the macro.

  12. #12
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Hi Ragulduy,

    Really appreciate your help, but I would like to do it myself as there are several such workbooks where I need to do this.


    Regards,
    Ashish

  13. #13
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Meanwhile,

    I have attached a sample sheet. in this case, need to remove 7 leading zeros.

    Regards,
    Ashish
    Attached Files Attached Files

  14. #14
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Hi, press alt+f11 to open the vba editor, select insert->new module and then post this code into the new module:
    Please Login or Register  to view this content.
    Then place the cursor between sub macro_1() and end sub and press F5 to run, whilst the sheet you want to change is active.

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Remove Leading zeros keeping hidden apostrophe as is

    I'm not sure why you are hung up about the leading apostrophe. That is a formatting character, and forms no part of the value that is in the cell. You can see this if you do:

    =LEFT(A2,1)

    which returns "0", or:

    =CODE(A2)

    which returns 48 (the ascii code for "0"). You can enter a leading apostrophe when you type an entry into a cell, to force the entry to be treated as a text value, so leading zeros can be retained, but this is a throwback to the old Lotus days. I think the Lotus Compatibility settings in Excel Options can give rise to the leading apostrophe when using Paste Special | Values (in older versions of Excel, at least).

    If you want to see the leading apostrophe explicitly, you can change my formula to this in B2:

    ="'"&IF(ISNUMBER(A2*1),TEXT(A2*1,"0"),A2)

    but then the apostrophe forms part of the value, rather than being treated as a formatting character, so when you fix the values in column B you will still see it displayed. A formula returns a value, not a format.

    Hope this helps.

    Pete

  16. #16
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Remove Leading zeros keeping hidden apostrophe as is

    I think this will give you what you want

    ="'"&MID(A1,MIN(FIND({1,2,3,4,5,6,7,8,9},A1&"0123456789")),SUM(LEN(A1)-LEN(SUBSTITUTE(A1,{0,1,2,3,4,5,6,7,8,9},""))))
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  17. #17
    Registered User
    Join Date
    12-23-2013
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: Remove Leading zeros keeping hidden apostrophe as is

    Ragulduy, Thanks a lot, it has helped!!

+ 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. Remove a leading Apostrophe
    By John Bates in forum Excel General
    Replies: 10
    Last Post: 09-09-2014, 07:41 AM
  2. Excel macro to automatically remove leading apostrophe from entire column
    By hk106 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2012, 10:38 AM
  3. Excel 2007 : Keeping leading zeros
    By 2007novice in forum Excel General
    Replies: 2
    Last Post: 06-07-2011, 04:22 PM
  4. [SOLVED]Remove Leading Apostrophe
    By eyeball11 in forum Excel General
    Replies: 2
    Last Post: 02-20-2011, 09:20 PM
  5. Keeping Leading Zeros
    By teddybouch in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-21-2008, 02:17 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