How to make your Excel VBA code run 1000 times faster

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 11. 07. 2024
  • 👉 Ready to master VBA?
    - Check out my full courses: courses.excelmacromastery.com/
    - Subscribe to the channel here: bit.ly/36hpTCY
    - FREE CHEAT SHEET: Get the free cheat sheet on VBA arrays here: bit.ly/2MXsnz9
    (Note: If the download page doesn't work then make sure to turn off any popup blockers)
    In this video I am going to take an Excel Macro and make it run 1000x faster.
    The code I'm using is a standard code you will see in the real-world. This code reads through 100,000 records and copies the rows which meet given criteria.
    Starting with very basic VBA code I will keep improving the code until it runs 1000+ times faster than the original.
    If you are creating Excel VBA code for real-world applications then you should take advantage of these proven techniques.
    Excel VBA Copy - The Complete Guide to Copying Data: (excelmacromastery.com/excel-v...)
    Shortcut Keys:
    Alt + F11: Switch between Excel and the VBA Editor.
    Ctrl + R: View the Project Properties Window.
    Ctrl + Shift + 8(or Ctrl + *): Get the current region on a worksheet.
    F5: Run the code from the current sub.
    F9(or click left margin): Add a breakpoint to pause the code.
    Tab: To move lines of code to the right(Indent)
    Shift + Tab: To move lines of code to the left(Outdent).
    Table of Contents:
    00:00 - Slide 1

Komentáƙe • 788

  • @wmcnabb
    @wmcnabb Pƙed 4 lety +122

    Paul, you are on fire of late! Some EXTREMELY useful techniques explained very well. I have always been able to tell the level of a developer by what stage they are at in these types of examples. I will be recommending this video to lots of people.

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety +5

      Hi Wyatt,
      That's actually a great point you make. It's like the evolution of a VBA developer. The begin using Select and activate and evolve through each stage from there.

    • @incobart
      @incobart Pƙed 4 lety +1

      @@Excelmacromastery hi, actualy I am looking your other video that explains it .. thanks

    • @prayushijain4087
      @prayushijain4087 Pƙed 4 lety

      Please provide your inputs
      Check this too
      czcams.com/users/ExcelAutomationByMudit

    • @TheZenytram
      @TheZenytram Pƙed 2 lety

      that pretty funny, i'm learning vba for the last 3 month, and this is precisely the steps i was taking it. Although i've stopped at the array level, i know that i'm miles away, too crude in the knowledge about the rest.
      This advanced filter, to me , looks like that i have found a treasure chest hidden somewhere.

  • @spamdump4459
    @spamdump4459 Pƙed 4 lety +22

    Saw this video and the next day reworked some macros I wrote for work. Previously if there were more than 20 files you might as well wander down the hall, pour a cup of coffee and when you got back it would be finishing, maybe. In less than a hour of recoding I had it down to 9 seconds! Today I got it under 2 seconds for 70 files.

  • @luciorlc
    @luciorlc Pƙed 3 lety +3

    I thank God because people like you exist.

  • @tequilacollins
    @tequilacollins Pƙed 4 lety +29

    I've been a very advanced VBA programmer for a lot of years, but still learned something new. Thanks.

  • @supplychainsys
    @supplychainsys Pƙed 4 lety +9

    Paul, you are one of the best overall coders I have found. You think out all the critical issues around a successful project - design, operational speed efficiency, code maintenance, user experience and project construction. It would be a joy to have you on or leading any team I have in the future.

  • @paulblackwood1273
    @paulblackwood1273 Pƙed 2 lety +1

    I really found these tips super easy to use and they allowed me to improve my spreadsheets performance 380x. Reduced run speed from 45 mins to 8 sec! Woohoo. The best one by far was reading the worksheet data into an array and processing it in memory rather than accessing the sheet. These instructions were so clear and easy to follow. Amazing. I even implemented the module timing in my code to target savings.

  • @christophseyfarth8018
    @christophseyfarth8018 Pƙed 4 lety +6

    One of the best and most useful Excel Videos found on the entire internet. Well Done and a big THANK YOU.

  • @orgilmas
    @orgilmas Pƙed 3 lety

    I feel happy that I use these techniques all the time when vba calculation time matters on some projects.

  • @Apsis0215
    @Apsis0215 Pƙed 11 měsĂ­ci +1

    Fantastic overview and breakout of the code! I never realized the cell to cell was so slow and traditional coding was so much faster (Arrays). That element collector trick is also very amazing!

  • @CharleyGR
    @CharleyGR Pƙed 4 lety +1

    Thanks a lot mate! I watched this video and two days later I got to apply those tips to a code that was taking around 5s to run. After making the changes it runs instantaneously which is how it was supposed to be. Keep up the good work!

  • @medasbabu
    @medasbabu Pƙed 2 lety

    Thanks Paul, Just completed coding to process 2.5 lakhs of records, its taking quite a lot of time, had to split it into 5 sets and run the code.
    This video provides, clear picture where i can improve my code and speed up the process.
    Thank you very much...

  • @onurtunc9468
    @onurtunc9468 Pƙed 2 lety

    Paul, you are always great teacher, i spent lots of times for copy and pasta data with criteria before but now this is amazing. Awesome. Thank you man.

  • @stevegarside5026
    @stevegarside5026 Pƙed 2 lety +1

    Hi Paul,
    Your videos and the way in which you explain them is to the highest level! Thanks for making our lives easier in the deep sea of code which we all love (some may hate I am sure haha).

  • @PeterrDDark
    @PeterrDDark Pƙed 4 lety +28

    This is absolutely amazing. I went from a run time of 6 minutes to 14 seconds! Thank you so much!

  • @EduardoRibeiroEdu
    @EduardoRibeiroEdu Pƙed 2 lety

    Man, this is the BEST VIDEO ON VBA in youtube! Thanks a lot.

  • @theexcelproject6973
    @theexcelproject6973 Pƙed 2 lety

    This is one of the most genuinely helpful contents I have ever come across.

  • @dr.frankpeffekoven9834
    @dr.frankpeffekoven9834 Pƙed 4 lety

    Thank you for the great video. I will now search for videos about advanced filters. With this technique I could solve the runtime problem with my program.

  • @user-dd1hj2rp7c
    @user-dd1hj2rp7c Pƙed 4 lety

    Here's a fan from Taiwan!! Thanks for this useful video, I learned a lot.

  • @hafizsiraaj
    @hafizsiraaj Pƙed 4 lety +1

    That is some very valuable techniques! Will definitely be using them to write/REwrite macros. Thanks! 😊

  • @datenshi1444
    @datenshi1444 Pƙed 4 lety +1

    This is exactly what I needed. Spot on. Thank you so much!

  • @free3690
    @free3690 Pƙed 3 lety

    This is an awesome improvements. I did not know there were so many ways to speed up the code! Thanks for sharing these tips

  • @martinargimon730
    @martinargimon730 Pƙed 3 lety

    Thanks for this tutorial. Is a MUST for all 'amateur' programmers like me. Excellent and Thanks once again Regards. Martin ( South Africa)

  • @atchoum87
    @atchoum87 Pƙed 4 lety

    Hi. i'm in the middle of creating an output sheet with a bunch of copy/paste from different sheets... Most useful youtube recommandation EVER! Thanks for the tips, it'll be very usefull

  • @blakemaster5054
    @blakemaster5054 Pƙed 4 lety

    Thanks Paul. This is the best video I've ever see in learning VBA for mastery. Thanks, i will watch all your 13 videos.

  • @brad7914
    @brad7914 Pƙed 4 lety +5

    Paul this is probably best Excel video I have ever watched - what you have shown is just amazing and something that will benefit me massively - thanks so much for sharing and keep up the great work!!

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety

      Thanks Brad. Glad you have got so much use from this video.

  • @andrewbarron6374
    @andrewbarron6374 Pƙed 4 lety +2

    Outstanding! I have been doing it the slow way for years.

  • @jeremybuchanan4759
    @jeremybuchanan4759 Pƙed rokem

    Thanks for this - I look forward to applying advance filter on current project.

  • @MarkCBB86
    @MarkCBB86 Pƙed 4 lety +1

    Probably one of the best VBA help videos I have seen, You explained each part very clearly without over speaking, Thank you.
    Things I learned from the video (MicroTimer, Resize, populating an Array straight from a range). I use assignment often, but looking forward to using it with Resize now.
    Favorite part of the Video is jumping to just using Advanced Filter - Sometimes we over code for things that there is already a built-in function for. Thanks again!!!

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety +1

      Thanks Mark. That is high praise indeed. I'm glad you got so much from the video.

  • @Lutfitince
    @Lutfitince Pƙed 4 lety +4

    AWESOME!!!
    That's the point of macros - speed!
    I am happy there are ppl like you

  • @sethvondardel5863
    @sethvondardel5863 Pƙed 4 lety +1

    Thank you so much for your great videos! You are great at explaining. Im learning a lot

  • @Greenham1988
    @Greenham1988 Pƙed 4 lety

    As the only accountant at my last two jobs that knew VBA, it's extremely refreshing to know others are using VBA at this level.
    I've always referenced your site, I did not know you had a CZcams channel, I've been on here just going through videos for (Repeating them of course) the last two days.
    Thank you so much for sharing this knowledge.

  • @jacek1366
    @jacek1366 Pƙed rokem

    Great tips, thank you!

  • @esrAsnataS
    @esrAsnataS Pƙed 2 lety +2

    As someone who loves Macroing :) everything I do in excel and who is totally self taught with the massive help of google, that was inspiring. One of the most helpful things I have seen.
    Thank you!!

  • @yveslitalien
    @yveslitalien Pƙed 4 lety +2

    Brilliant! I just learned lots and just wish I had known this a long time ago!

  • @jeroldjay1711
    @jeroldjay1711 Pƙed 4 lety +7

    I really wish I had watched this two years ago!! It would have saved me a lot of time learning some of these techniques the hard way!!

  • @jeffchen6556
    @jeffchen6556 Pƙed rokem

    You are the best VBA teacher of me, many thanks

  • @IanLockley
    @IanLockley Pƙed 4 lety +2

    Paul, you've blown me away! I'll be using these techniques to vastly improve the speed of my current Excel projects. Some of my projects take 10 to 15 minutes. This is bonkers! I've been writing the most inefficient code possible.

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety +1

      Thanks Ian. Don't worry we've all been there. The Copy and Paste method is so common place in VBA web examples that when I discovered assign I was sure it couldn't possibly be better than Copy and Paste.

  • @martiancocian6301
    @martiancocian6301 Pƙed 2 lety

    I am speechless. This is wonderful stuff. Thank you for sharing. God bless!

  • @EliasGonzales
    @EliasGonzales Pƙed 4 lety

    Bravo!! great tutorial. It help me a lot to improve my data processing from multiple worksheets. Thanks a lot!

  • @danteencinas7020
    @danteencinas7020 Pƙed 2 lety

    Wow... Nice... Advanced filters blew my mind! Thank you!

  • @meiwong5615
    @meiwong5615 Pƙed 4 lety +4

    Best VBA tutorials I’ve seen so far!

  • @matthewverhage1282
    @matthewverhage1282 Pƙed 4 lety +2

    Wow, one of the best VBA videos I've ever seen. Very helpful and everything explained very straight forward! I like that I wouldn't necessarily use everything, but the step by step way you explained each thing you did makes it easy to apply where it makes the most sense. Well done!

  • @user-sv7pj5hx8t
    @user-sv7pj5hx8t Pƙed rokem

    Hats off to you sir. Big help. Im running a small engineering calculation. but still there are hundreds of sheets need to be duplicated. these tips improve it by a lot.

  • @alphonsoba8171
    @alphonsoba8171 Pƙed 4 lety +1

    As usual, thanks Paul. While I use the web a lot for examples, you are the only one I keep track of. Love your stuff.

  • @manjunathmahamuni4120
    @manjunathmahamuni4120 Pƙed 2 lety

    wow !! The Awesome techniques I got today from your channel, Thank you very much for this great knowledge !!

  • @TheSybolt
    @TheSybolt Pƙed 2 lety

    Great stuff Paul, thanks a lot for this video.

  • @MrZH6
    @MrZH6 Pƙed 4 lety

    That's awesome. Thanks for the video!

  • @BrendanOD
    @BrendanOD Pƙed 4 lety +51

    Instead of setting calculation to automatic at the end, it’s best practice to capture the current calc mode at the beginning. And set it back to that at the end. Manual calc may have already been set in Excel, a macro that turns it back on can be an annoyance.

  • @Mraungnaingthu1
    @Mraungnaingthu1 Pƙed 2 lety

    Your live explanation is precious for me.

  • @itsdaj
    @itsdaj Pƙed 11 měsĂ­ci

    This is the double slit experiment for Excel. Thank you for breaking this down.

  • @darianleduc
    @darianleduc Pƙed 3 lety

    Excellent! Thx. Extremely important concept in VBA

  • @dst47
    @dst47 Pƙed 4 lety +2

    Much appreciated. My excel calculation time has dropped from 20 mins to 5mins. It saved lot of time of my life. Thank you so much.

  • @rasmusravnsbjergbyriel2846
    @rasmusravnsbjergbyriel2846 Pƙed 4 lety +1

    I think this may have been THE best VBA advice I have ever seen. Working in a large company everyday, sometimes handling hundredthousands of lines of data, I can't wait to implement these advice in my future work. And maybe even rework some of my existing code.

  • @jeromecordel5908
    @jeromecordel5908 Pƙed 4 lety +3

    A major work !
    Very helpful and easy to integrate in all VBA code.
    Thank you so much

  • @frederickleung7460
    @frederickleung7460 Pƙed 4 lety

    Great work !!!! Thanks

  • @wilgo58
    @wilgo58 Pƙed 4 lety +2

    Thank you sooo much. You have taken my code and shortened it's run time by quite a bit :)
    I still need to learn and understand the Advanced Filter a little better, but you have helped improve my workload significantly.
    I truly appreciate it :)

  • @WeisSchwarz
    @WeisSchwarz Pƙed 4 lety

    Great video!! I just watched this one video of yours and I subscribed. Good job!!

  • @tocobern
    @tocobern Pƙed 4 lety

    Brilliant, well explained. I've not used vba for years and I was helping someone out with something urgent for their work. I got what they needed sorted out but my process was running so slow. They are giving a demonstration today but it's been annoying me that it's taking around 2.30mins to run through about a thousand records. Now I see its because I am making all these select cut paste onto different worksheets. I will use some of the techniques you so brilliantly explained. So I had to subscribe. Thanks again.

  • @sacha7407
    @sacha7407 Pƙed 4 lety

    I program in VBA for over 10 years and I have learned again some things. Thank for this video very clear
 even for a french with poor english

  • @danfoltz9947
    @danfoltz9947 Pƙed 2 lety

    This is amazing. I wish I had found your site some time ago. I do have a couple of applications that I want to update. I am anxious to see how fast I can make them run. Thanks for this video.

  • @jennydrumm7223
    @jennydrumm7223 Pƙed 4 lety +1

    This is my first time seeing one of your videos and I'm impressed! Your explanation made complete sense, at least while I was watching and listening to you. I'm going to have to watch it a couple more times to get it to stay in my head, LOL! But your directions are clear, pretty easy to understand and the visuals going right along with your narration is VERY helpful to me! Thanks!

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety

      Thanks for the feedback Jenny. I'm glad you got so much value from the video.

  • @ThinkBigToday
    @ThinkBigToday Pƙed 4 lety

    Great video, one of the better videos I ever watched on VBA and I have been coding / learning for few years

  • @garriedaden4168
    @garriedaden4168 Pƙed 4 lety

    Really helpful. Many thanks.

  • @jawalim1996
    @jawalim1996 Pƙed 4 lety +1

    love from first video.. This is impressive and extremely useful.
    You are outstanding in both, knowledge and ease of explaining complicated stuff.
    Thank you for sharing. Would love to see more of practical videos like this from you.

  • @twospooky6266
    @twospooky6266 Pƙed 4 lety +2

    Eye opening stuff! Thanks Paul.

  • @ericjudd9198
    @ericjudd9198 Pƙed 4 lety

    Thank you for sharing this, Paul. These tips are extremely helpful.

  • @engt1000
    @engt1000 Pƙed 4 lety

    Wow! Great info. Thanks for the tips.

  • @MalinaC
    @MalinaC Pƙed 4 lety

    I love this advanced filter trick! Thanks for sharing!

  • @andresbambarenalcala8866
    @andresbambarenalcala8866 Pƙed 4 lety

    EXCELLENT, WONDERFUL, THANK YOU SO MUCH FOR YOUR CONTRIBUTION OF KNOWLEDGE

  • @freeliberalminds
    @freeliberalminds Pƙed rokem

    Great VBA helpful video tips from you sir Paul.

  • @pe00100
    @pe00100 Pƙed 4 lety +1

    I write lots of VBA code and I learned new tricks. I never used the advanced filter before. Thanks for creating this overview.

  • @shohanmohammadwasiuzzaman1111

    Clearly, the guidelines have improved the speed of my code... excellent & simple techniques... thanks

  • @Excelmacromastery
    @Excelmacromastery  Pƙed 4 lety +39

    Hi everyone!
    This video has some great practical techniques to help you speed up your code.
    Please add any comments below.
    Thank you.

    • @8ballWASD
      @8ballWASD Pƙed 4 lety

      thank you, Mr Paul! I'm going to implement it in my team. I wish you all the best in your career!

    • @amareshachar4335
      @amareshachar4335 Pƙed 4 lety

      Hello Sir.. I have below code in my file.. it takes about 10 seconds to run.. how can we get it work faster..!?
      Sub do_it()
      For r = 7 To 18
      Range("K" & r & ":L" & r).Value = Range("I" & r & ":J" & r).Value
      If Cells(r, "G") "" Then Cells(r, "K") = Cells(r, "G")
      If Cells(r, "H") "" Then Cells(r, "L") = Cells(r, "H")
      Next r
      End Sub

    • @sonderfall1979
      @sonderfall1979 Pƙed 4 lety

      Hi, I have two questions: 1) I have an Excel simulation where I have 15'000 clients and want to run 10'000 scenario. At the end I'll produce four matrices (15'000 times 10'000 times 4). It takes about 36 minutes for 1000 scenarios and I already worked with arrays (as good as I could with my limited knowledge). Do you think it is possible to store up to 0.6 billion data records in Excel or do you have a tip what to do because Excel almost breaks down ;-). Should I "outsource" data into CSV-spreadsheets instead? 2) Do you know a good random number generator in VBA. I tried to use the "built in" random number generator but somehow it didn't work with my array code.

    • @plumberski8854
      @plumberski8854 Pƙed 4 lety

      Read that Excel 2016 32 bits has a file size problem running VBA when it is greater than 50 Mb. True? If so, why? 50 Mb is not that big.

    • @prayushijain4087
      @prayushijain4087 Pƙed 4 lety

      Very nice video...
      Please provide your inputs
      czcams.com/users/ExcelAutomationByMudit

  • @Abbermist
    @Abbermist Pƙed rokem

    Excellent - thank you.

  • @MyFlopsi
    @MyFlopsi Pƙed 4 lety +1

    A big thanks from Germany for this very useful und powerful way to code, people like you make this world better!

  • @lyonhard1
    @lyonhard1 Pƙed 4 lety

    Thanks Paul, Timely informative, and pertinent, as usual.

  • @gestionsigdata
    @gestionsigdata Pƙed 4 měsĂ­ci

    Perfect. Excellent. Thanks a lot to take the time to teach us how to become our codes faster. Greetings from Venezuela. New Follower.

  • @eddai84
    @eddai84 Pƙed 3 lety

    Thanks for sharing. Excellent techniques. God bless you.

  • @iqbaluk
    @iqbaluk Pƙed 4 lety

    Loved this Advanced filter

  • @aguswidi9316
    @aguswidi9316 Pƙed 4 lety

    Thank's a million, now I'will review all vba macro code cause now i'm using excel 2016, which is slowing down my macros.

  • @tomcarnahan3898
    @tomcarnahan3898 Pƙed 4 lety

    Wonderful! Keep up the good work!

  • @ricomajestic
    @ricomajestic Pƙed rokem

    This guy definitely knows his stuff! I am impressed.

  • @ardeshiraqayi9976
    @ardeshiraqayi9976 Pƙed 4 lety

    AWESOME ! .... Super professional ........

  • @chrishartnell8936
    @chrishartnell8936 Pƙed 4 lety

    Thanks Paul, I like your clear step by step style. This bite sized video will have a significant impact on my approach to some tasks and see I will have to rewrite a batch of my existing routines! Using the advanced filter looks like a much more efficient,simpler and cleaner approach than pivot tables/ordinary filters to do the heavy lifting.

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety

      Great you found it so useful Chris.
      Advanced filter are great for copying and filtering data in record format. They are not only fast but require less code and it's simple to select or reorder columns.
      The one advantage that pivot tables have is that they group data whereas the advanced filter simply filters it.

  • @vemaakademia427
    @vemaakademia427 Pƙed 4 lety +1

    Paul, this is great! Thanks. I learned something new and useful today.

  • @yurd563
    @yurd563 Pƙed 4 lety

    Thanks for video!

  • @miketucker246
    @miketucker246 Pƙed 4 lety

    Great video mate. Thanks for the heads up on arrays.

  • @simplejuan
    @simplejuan Pƙed 4 lety

    Thank you I learned a lot from this video.

  • @anilthakkar2372
    @anilthakkar2372 Pƙed 2 lety

    You are just Great Sir with immense knowledge

  • @giacominoveltri4188
    @giacominoveltri4188 Pƙed 4 lety

    I was aware of some of the tricks, but not really aware of the really big ones. Thank you! Well done.

  • @JohnOvens
    @JohnOvens Pƙed 4 lety +3

    Hi Paul, this is absolutely fantastic - I have watched it several times and made copious notes. I hope to be able to implement it in my personal stock recorder program
    John

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety

      Hi John,
      Great to hear from you as always. Thanks for the feedback. I will be releasing plenty of new videos in the coming weeks so key an eye out for them.
      Regards
      Paul

  • @ZEUSAIMIGHTY
    @ZEUSAIMIGHTY Pƙed 4 lety +2

    Wow, I literally ran my VBA exactly how you said beginners do but that's only because that's how the record macro feature told me to. Very helpful!

    • @Excelmacromastery
      @Excelmacromastery  Pƙed 4 lety

      Thanks Nick. The macro recorder code is very different than real-world code. It leads to a lot of confusion.

  • @ypyang772
    @ypyang772 Pƙed 4 lety

    This blow my mind...thanks a lot.

  • @lfqme
    @lfqme Pƙed 4 lety

    Paul, thanks a lot for share this knowledge with us. This is really useful for the daily job.
    Go ahead with your valuable work spreading all your knowledge. 👏👍

  • @moshemoses6249
    @moshemoses6249 Pƙed 2 lety

    This is amazing.
    I am so using this! Thank you

  • @aaronorelup4024
    @aaronorelup4024 Pƙed 2 lety

    Wow, just awesome!

  • @engineeringinspectionsirel1385

    Great video Paul. Excellent explanation, very well presented and so clear.

  • @GanovAlex
    @GanovAlex Pƙed 3 lety

    very useful, thanks a lot

  • @kolinsin23
    @kolinsin23 Pƙed 3 lety

    Didn't comment first time watching this, advanced filter method is my "go-to" for any code that needs a copy paste. On average, has mitigated 96% waste generation (time) based on original process. Thanks for sharing :)

  • @kaisun1661
    @kaisun1661 Pƙed 4 lety

    Thank you, I tried the first two steps, and increase 10 fold of the speed of my worksheet. Thank you for sharing!