+ Reply to Thread
Results 1 to 14 of 14

Code Efficiency - Adding formulas and exporting to text files

  1. #1
    Registered User
    Join Date
    12-08-2015
    Location
    Birmingham, England
    MS-Off Ver
    2007
    Posts
    44

    Code Efficiency - Adding formulas and exporting to text files

    Hi there,

    I am hoping someone may be able to offer suggestions about how I can make my code more efficient as it is very slow to run? Essentially it adds a formula in column A and a formula in column B, for any number of rows. It then exports each column into 2 separate text files.

    Thanks in advance.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Code Efficiency - Adding formulas and exporting to text files

    Without even looking at your export function, how about replacing this
    Please Login or Register  to view this content.
    With this:
    Please Login or Register  to view this content.
    Tim
    Never stop learning!
    <--- please consider *-ing !

  3. #3
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Code Efficiency - Adding formulas and exporting to text files

    Then... looking at your export routine, try using an array to set up the print and send it all to the file(s) in one fell swoop:
    Please Login or Register  to view this content.
    Getting rid of the loops will invariably make the code much faster. Maybe someone else can come up with a better solution (I'd still consider myself a beginner), but that could be a start.

    Tim

  4. #4
    Registered User
    Join Date
    12-08-2015
    Location
    Birmingham, England
    MS-Off Ver
    2007
    Posts
    44

    Re: Code Efficiency - Adding formulas and exporting to text files

    Thanks, that definitely helped a lot!

    The only issue now is that the data in the text file is all in one block whereas before it separated on each line. Do you know if I could get it back to line separated please?

    Many Thanks

  5. #5
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Code Efficiency - Adding formulas and exporting to text files

    Sorry, don't get on here much during the week at the moment.

    Strange, the text files from my sample are showing with each entry on a separate line (see attached)... Exactly the same output as when I use your code.

    BTW, I realised that using char(10) as separation character doesn't really have an effect since print writes each value from the sCellx array on a separate line anyway.

    Tim
    Attached Files Attached Files
    Last edited by harrisonland; 05-22-2020 at 09:28 AM.

  6. #6
    Registered User
    Join Date
    12-08-2015
    Location
    Birmingham, England
    MS-Off Ver
    2007
    Posts
    44

    Re: Code Efficiency - Adding formulas and exporting to text files

    Hey Tim,

    They seem to be all in one block in your text files too? There is just one line with "ABCDE...".
    Each row in excel should have one line in the text file so if there are 100 rows in excel, there should be 100 lines in the text file.

    Appreciate your help with this.

  7. #7
    Valued Forum Contributor
    Join Date
    06-22-2018
    Location
    Blackpool, England
    MS-Off Ver
    2019
    Posts
    408

    Re: Code Efficiency - Adding formulas and exporting to text files

    Definitely showing multi-line output. See attachment.
    Attached Images Attached Images

  8. #8
    Registered User
    Join Date
    12-08-2015
    Location
    Birmingham, England
    MS-Off Ver
    2007
    Posts
    44

    Re: Code Efficiency - Adding formulas and exporting to text files

    Hmm yeah it's strange. If I open your text file on my phone, it shows multi line output but if I open it (or run it myself) in Notepad on my PC, it shows only one line.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,572

    Re: Code Efficiency - Adding formulas and exporting to text files

    Have you selected Word Wrap when you view the file(s) in Notepad?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  10. #10
    Registered User
    Join Date
    12-08-2015
    Location
    Birmingham, England
    MS-Off Ver
    2007
    Posts
    44

    Re: Code Efficiency - Adding formulas and exporting to text files

    No, Word Wrap is off..


    Attachment 679493

  11. #11
    Registered User
    Join Date
    12-08-2015
    Location
    Birmingham, England
    MS-Off Ver
    2007
    Posts
    44

    Re: Code Efficiency - Adding formulas and exporting to text files

    Ok after some more digging, it seems it is a Notepad issue.

    https://superuser.com/questions/3620...ing-linebreaks

    "Notepad only recognises CR, LF (0x0d, 0x0a), whereas other sources might use CR only, or LF only."

    Is there something in your code that I'd need to change to accommodate this? Perhaps char(10)?

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,572

    Re: Code Efficiency - Adding formulas and exporting to text files

    Mmmm, you need to switch Word Wrap on.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,572

    Re: Code Efficiency - Adding formulas and exporting to text files

    Maybe change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and same for sCell2.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,572

    Re: Code Efficiency - Adding formulas and exporting to text files

    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. [SOLVED] Exporting all Formulas and Code used in a Workbook
    By davo3286 in forum Excel General
    Replies: 1
    Last Post: 09-12-2018, 11:04 AM
  2. [SOLVED] Adding a searchbox and exporting data from a row to a new template (have existing code)
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-09-2013, 06:45 AM
  3. [SOLVED] Exporting filled rows into individual text files
    By mockingjay3 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-21-2013, 05:34 AM
  4. Exporting files to text files
    By excelvraag in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 08-22-2012, 10:33 AM
  5. [SOLVED] Code Efficiency [77 files, 1.04MM lines, 647MB]
    By gwebb in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-13-2012, 05:01 PM
  6. Exporting files to text
    By skartykn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2012, 03:47 AM
  7. Help exporting columns into multiple text files
    By vund0 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-02-2011, 05:09 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