+ Reply to Thread
Results 1 to 20 of 20

Macro delete trailing spaces (1 million line file)

  1. #1
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Macro delete trailing spaces (1 million line file)

    Hi,
    I'm willing to delete trailing spaces in my file, but my file is huge: 15 col, 1 million lines. I know it's crazy, it will go very soon in a stat software.
    For column A try this...

    I found that code, but only worked for col A: what can I do ?
    HTML Code: 
    Also I found that:
    HTML Code: 
    But it does not work.

    I have often a problem of capacity (error 6), since the file is huge.


    Someone got an idea for that ?


    thanks a lot,


    Aya

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro delete trailing spaces (1 million line file)

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro delete trailing spaces (1 million line file)

    Hi Aya

    Have no idea if this will work on that much Data but you can try this...
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Re: Macro delete trailing spaces (1 million line file)

    Hi! thanks for your macros

    it works, but not for all the file, at a certain point, excel get blocks. MAc says: excel does not respond. So I stop it
    weird, isnt ?
    Should I wait even 30min when it says "excel does not answer" ?

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro delete trailing spaces (1 million line file)

    Hi Aya

    If the message is "Excel is not responding", it's my experience that it doesn't mean it's not working. You have a LOT of cells that are being massaged.

    Do ALL Columns require trimming or only certain Columns? If ALL Columns it may take hours to complete...if certain Columns perhaps we can address that and speed things up.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro delete trailing spaces (1 million line file)

    Hi Aya & jaslake,

    How about:

    Please Login or Register  to view this content.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  7. #7
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Re: Macro delete trailing spaces (1 million line file)

    I see
    it's interesting. I think i'll wait. Now i'm not in my home town, in my home town i usually use Kutools for PC and it's very quick. For the moment, I'll make a test tomorrow letting your macro (which works well) acting on the file for 1 or 2 hours. I'm sure it will work.

    The problem is that I'll receive lots of files, with maj and accents and trailling issues, somethines in 10 columns, sometimes in 3, so it will depend....

    Anyways i'm happy that you said that:
    HTML Code: 

    thanks! i'll let u know!

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro delete trailing spaces (1 million line file)

    15 columns and 1m rows is a no-go area for a loop, even an array loop will struggle. Perhaps, you can divide your data in to manageable rows and once the data are clean, you can re-merge them in to a single sheet. But there is a fundamental issue which you need to address. Why are using excel up to 1m rows? Excel is not designed for storing data, not surely for a string type of data. My guess is these data are probably imported from another system.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro delete trailing spaces (1 million line file)

    Good catch Winon...wrote the Code on the fly...should have added Calculation and Screen Updating to the Code.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro delete trailing spaces (1 million line file)

    Hi Aya

    Are they ALWAYS the SAME 3 Columns (or 10 Columns)?

  11. #11
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Re: Macro delete trailing spaces (1 million line file)

    Hi !

    These are data on corporations provided by some central banks. i'm sure these data are in CSV or .dta originally, and they exported them to excel in order to send me. And indeed it will be an issue because they will continue sending me such datas.

    Before, the data were divided by year in several worksheets, 30 in one of the files. I merged them all together before beginning to clean the accents etc.

    And no it will not always be the same columns i guess. Usually the problematic columns are the one with the sector, that's all.


    What other softwares and process options would you recommend to clean these data ?

    The final objective is actually to put that in Stata, but before, i have to clean the data, and probably do a lot of SearchV to add infos to these data. And wel, sometimes search something in the excel fiel, but mainly use stata.
    Last edited by Ayadin; 08-11-2016 at 04:04 AM.

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

    Re: Macro delete trailing spaces (1 million line file)

    If it is a csv file, it would be better/faster to edit csv directly then open it with Excel.

  13. #13
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Re: Macro delete trailing spaces (1 million line file)

    Ok. What I can do is to transfer excel to csv, edit, and go back to excel ? What do you think ?

    How do we edit a csv ? With the simple replace tool ?

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro delete trailing spaces (1 million line file)

    You have answered my question. Just clean the data before you merge them.

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

    Re: Macro delete trailing spaces (1 million line file)

    This will create a new csv file, so you can open it from excel.
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Re: Macro delete trailing spaces (1 million line file)

    Hi created the csv file using "register as csv file" actually. Is it the same ?

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

    Re: Macro delete trailing spaces (1 million line file)

    Quote Originally Posted by Ayadin View Post
    Hi created the csv file using "register as csv file" actually. Is it the same ?
    I don't understand what you mean.

    If you run the code and select the CSV file that you want to trim, it will create a new csv file in the same folder under the name of
    "YourFileName_Trimmed.csv".
    Where "YourFileName" is from original file name.

    Then you can open it from Excel.

  18. #18
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Re: Macro delete trailing spaces (1 million line file)

    Is it lighter to open that csv fle in excel than to work with the former excel file i got ?
    Is there any automation i can use to edit the csv file ?

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

    Re: Macro delete trailing spaces (1 million line file)

    OOps, 2011...

    You are on Mac, so my code will not work.
    Sorry.

  20. #20
    Registered User
    Join Date
    06-09-2016
    Location
    Paris
    MS-Off Ver
    2011
    Posts
    52

    Re: Macro delete trailing spaces (1 million line file)

    it's fine, i have a simpler way to make the csv file!

    Should i now open the csv file in excel to edit it ?

+ 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 leading and trailing spaces in each new line break in cell
    By halo12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2015, 07:10 AM
  2. [SOLVED] VBA Code to delete trailing spaces:
    By Chad Bateman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2015, 05:56 PM
  3. Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM
    By Zach51215 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-20-2013, 04:24 PM
  4. Delete all trailing and leading spaces in multiple .csv files
    By rob_ford16 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-11-2013, 12:51 PM
  5. delete leading trailing and excessive spaces
    By djwaz69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-28-2012, 03:59 AM
  6. Delete trailing spaces & characters
    By bigband1 in forum Excel General
    Replies: 2
    Last Post: 03-06-2012, 04:24 PM
  7. Excel keep trailing spaces for prn
    By DKY in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2011, 03:54 PM

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