+ Reply to Thread
Results 1 to 14 of 14

Macro to create csv file delete leading zeroes

  1. #1
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Macro to create csv file delete leading zeroes

    HI I have below code which have to make a csv file in Cell B1 separated by "Q, Q".. My problem is what ever i do, it delete the leading zeroes, and i need that to use this in other application.


    Pasted in from A2

    00002851
    00011941
    00014457
    00014785
    00015943
    Result is like this in cell B1 Q2851Q, Q11941Q, Q14457Q, Q14785Q, Q15943Q So the leading zeroes is gone.

    Please have a look in below code and see if some can help. Actually i need after to replace the all teh Q with ". But i cant do in the first run.

    But the leading zeroes is the problem

    Please have a look

    Sincerely

    Abjac

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to create csv file delete leading zeroes

    Hi Abjac,

    Try the following which should keep your leading zeros.
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,885

    Re: Macro to create csv file delete leading zeroes

    I used your code and was able to produce what I believe is the desired result.

    Data Range
    A
    B
    C
    D
    E
    F
    G
    1
    00002851
    00002851Q, Q00011941Q, Q00014457Q, Q00014785Q, Q00015943
    2
    00011941
    3
    00014457
    4
    00014785
    5
    00015943

    but it appears that the Q is sometimes misplaced.

    EDIT: Looks like Lewis has your result for you.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation


    Hi !

    abjac, your code works like a charm on my side ! With exact entries as described. (ex: 00002851)
    Same result as previous post …

    And one year ago in one of your previous threads with same subject to export a csv file,
    I already gave you a code to create such a csv file !
    Last edited by Marc L; 07-19-2015 at 11:22 AM.

  5. #5
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Macro to create csv file delete leading zeroes

    HI To all of you. I am really surprised about this. Dont know what is wrong. I upload the testfile now. I use excel 2013 now, dont know if that make a change. But i cant make this work. Please have a look at below test sheet. Both codes are inside.

    Thanks in advance

    Sincerely
    Abjac
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to create csv file delete leading zeroes

    Hi abjac,

    The problem seems to be not with the code, but with your data.

    None of your data has any leading zeros. We can put in leading zeros with this data if you tell us how wide your fields are (they appear to be 8 digits).

    Alternatively you can:
    a. Format your cells as Text.
    b. Put a leading apostrophe (') in front of the data, which will keep the leading zeros if there is any in the data (i.e. this treats the data as text.

    Alternative Macro for 8 digits:
    Please Login or Register  to view this content.
    Lewis

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation

    Quote Originally Posted by abjac View Post
    Please have a look at below test sheet. Both codes are inside.
    Where are "leading zeroes" in your attached file ?‼

  8. #8
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Macro to create csv file delete leading zeroes

    Sorry i am getting old. I try again with the leading zeroes in the column. LJMetzger. Your code give leading zeroes i just checked it.
    But i can tell why i need the Q. In the application i have to paste this in, The separator has to be like this. ": ", but i cant put that into the code-
    it would look like this then. "": "". That s why i replace the " with a Q and after i replace the Q with a ". SO when finish the separation will look like this. 00002851": "00011941.

    Where in your code can i change this? And sorry now i will attach a sheet with the leading zeroes thanks.

    Sincerely

    Abjac
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to create csv file delete leading zeroes

    In the Macro you should be able to replace the "Q" with any character you want including ":" and ".". You may want to eliminate and/or modify one or more of the following to get your desired results:
    a. The first "Q"
    b. The last "Q"
    c. The comma between items

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Macro to create csv file delete leading zeroes

    Quote Originally Posted by abjac View Post
    SO when finish the separation will look like this. 00002851": "00011941.
    try
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Macro to create csv file delete leading zeroes

    HI LJMetzger. I tried your code and if i put it together with a replace it give me the result i want. Jindon thanks allot. Your code works, but i need it displayed in exsample cell B1 so i can copy it after to another application.

    But thanks allot really great help here.

    Below is the code i landed on and its working for sure

    Thanks

    Have a nice day

    Sincerely

    Abjac

    Please Login or Register  to view this content.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Macro to create csv file delete leading zeroes

    If that is the result that you want then
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Macro to create csv file delete leading zeroes

    Thanks Jindon like normal your codes are brilliant. This one as well it works just perfect. Thanks allot.

    Have a nice day

    Sincerely

    Abjac

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Macro to create csv file delete leading zeroes

    You are welcome and thanks for the rep.

+ 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. Replies: 2
    Last Post: 05-07-2015, 04:15 AM
  2. Add zeroes within dates (NOT leading zeroes)
    By anthony19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2012, 04:08 PM
  3. Leading Zeroes & XML
    By jlhart76 in forum Excel General
    Replies: 4
    Last Post: 06-03-2009, 08:23 PM
  4. Keeping Leading Zeroes
    By EmmaG1959 in forum Excel General
    Replies: 2
    Last Post: 04-09-2008, 05:39 AM
  5. [SOLVED] How to preserve leading zeroes
    By pbrase in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2005, 02:10 PM
  6. [SOLVED] Leading Zeroes
    By Ken in forum Excel General
    Replies: 1
    Last Post: 10-07-2005, 11:05 AM
  7. [SOLVED] No decimals and leading zeroes
    By gcotterl in forum Excel General
    Replies: 2
    Last Post: 04-18-2005, 02: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