+ Reply to Thread
Results 1 to 13 of 13

Optimize VBA Code without Copy&Paste

  1. #1
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Optimize VBA Code without Copy&Paste

    Dear Community,

    See Attached File.

    I have Jindon's code for "Sorting", but I'm trying to Loop through each column list, copy&pasting into Jindon's code for "Sorting".



    Why does Version1() macro work 100% fine (but takes 3 seconds per loop), but Version2() macro does not work at all, and gets poopy results?
    Please Login or Register  to view this content.

    Trying to OPTIMIZE with Version2()

    Please Login or Register  to view this content.
    I'm trying to Optimize the Version1() macro to eliminate any inefficiency, such as elimianting copy&paste, because I calculate it may take 26 hours to do 16,000 loops at 3 seconds each.
    Attached Files Attached Files
    Last edited by rwat1; 09-24-2018 at 01:19 AM.

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

    Re: Optimize VBA Code without Copy&Paste

    Try
    Please Login or Register  to view this content.
    Last edited by jindon; 09-24-2018 at 01:35 AM.

  3. #3
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    Jindon,

    May you and your entirely family be BLESSED with good fortune, prosperity, love, and happiness by God for generations upon generations.... for all of eternity.

    You literally saved my life.
    Last edited by jeffreybrown; 10-08-2018 at 10:34 PM. Reason: Removed full quote!

  4. #4
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    Dear Jindon,

    I got really excited but I noticed the Sorting is like this:

    a1
    a2
    a3
    b1
    b2
    b3
    c1
    c2
    c3

    Could you sort it like this?

    a1
    b1
    c1
    a2
    b2
    c2
    a3
    b3
    c3
    Last edited by jeffreybrown; 10-08-2018 at 10:34 PM. Reason: Removed full quote!

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

    Re: Optimize VBA Code without Copy&Paste

    Replace the function with
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    jindon,

    My Professor says he is gracious and very appreciative of all the help you given us! Thank you so much! You are #1 the best, God bless you!
    Last edited by jeffreybrown; 10-08-2018 at 10:35 PM. Reason: Removed full quote!

  7. #7
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    Dear Jindon,

    Sorry to bring this up again, but For the past 14 days, I worked tirelessly trying to get this code to run for my Professor...I'm super desperate.


    The code you gave me worked very well for small number of columns (~10 columns), but at larger number of columns (15,000 columns), it just doesn't really work (data isn't copy and pasted)


    I don't know why it works with 10 columns, but for 15000, it finishes, but the data doesn't appear to be sorted? (i'm thinking my code is not well optimized)
    See below attached file:
    Last edited by jeffreybrown; 10-08-2018 at 10:35 PM. Reason: Removed full quote!

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

    Re: Optimize VBA Code without Copy&Paste

    I don't know why it works with 10 columns, but for 15000, it doesn't work or gets clogged up.
    I don't understand why it is doesn't work and I can not replicate the issue.
    Upload a workbook that doesn't work.

  9. #9
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    Quote Originally Posted by jindon View Post
    I don't understand why it is doesn't work and I can not replicate the issue.
    Upload a workbook that doesn't work.

    You are right, I've uploaded this Worksheet which has 1000 columns, and only Loop it twice (Max = 2) so loop twice for macro Official(), but goes frozen or takes a super long while to event complete 2 loops with so much columns....

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

    Re: Optimize VBA Code without Copy&Paste

    Just tested in Sheet2 and all is working fine.
    If it goes 15000 columns, it may get slower, but it should work still.

  11. #11
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    Quote Originally Posted by jindon View Post
    Just tested in Sheet2 and all is working fine.
    If it goes 15000 columns, it may get slower, but it should work still.
    I'm crossing my fingers but Jindon, you are right, the code DOES work.

    I switched to another laptop (32bit Excel), and it works flawlessly, even up to 16,000 columns

    My "gaming laptop" (64bit Excel) just crashes, maybe I need to do a fresh-reinstall of entire Windows or Excel! Irony is that my other laptop sucks, yet it can perform 16K columns just fine

    Thank you so much Jindon for giving me the idea to try another laptop. I was going insane....

    God bless you Jindon, I LOVE YOU for all the help you give me :-)
    Last edited by rwat1; 10-08-2018 at 10:35 PM.

  12. #12
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    Quote Originally Posted by jindon View Post
    Just tested in Sheet2 and all is working fine.
    If it goes 15000 columns, it may get slower, but it should work still.
    Dear Jindon,

    The Excel works flawlessly for a typical format (e.g. AXXX, where A is alphanumeric, and XXX is numeric).... but when it strays in non-typical format, it gives a run-time error '5' (see attached file)

    Can you modify the code so it ignores all these non-typical formats (e.g. "AA232-333" or "E or K (location amibigous)) or put them at the bottom of the list?

  13. #13
    Registered User
    Join Date
    09-19-2018
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Optimize VBA Code without Copy&Paste

    What I realized I was working on a 2013 Laptop with only 12GB RAM. When I switched to a newly built desktop PC with 32GB of RAM, much more powerful CPU, then it doesn't crash or freeze.

+ 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. Need to optimize the code
    By pm.patel189 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2018, 01:06 PM
  2. [SOLVED] Optimize code copy very slow
    By JohnGreen2 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-21-2017, 04:20 AM
  3. Optimize a code
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2015, 05:31 PM
  4. Optimize code
    By DarkKnightLupo in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-19-2014, 08:58 AM
  5. Optimize code
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2011, 03:35 PM
  6. Optimize VBA code
    By doodlebug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2007, 07:53 AM
  7. Optimize copy/paste loop
    By aldsv in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-09-2005, 06:07 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