+ Reply to Thread
Results 1 to 4 of 4

Help with speed issues in a macro

  1. #1
    Registered User
    Join Date
    01-24-2011
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    19

    Help with speed issues in a macro

    I use Excel 2007. Let me state that I am by no means a programmer in VB. A lot of the macros I create, I do so by trial and error, and a lot of Google searching.

    Below is my code. The macro *does* work. The only issue is that when it gets to a certain step, it takes longer to perform it than if I were to do it manually. It seems like the step that takes long is the "ActiveSheet.Paste" step. It takes upwards of 20 seconds. I get the "calculating" message in the lower right corner of the document. Yet, if I were to paste the formula manually, it calculates almost instantly.

    Am I doing something wrong here?

    thanks,
    mike.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 01-24-2011 at 09:12 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help with speed issues in a macro

    Hello diggeryo,

    Welcome to the Forum!

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time. This will eliminate the need to add spaces to your code.

    How to wrap your Code using the # icon
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    To manually wrap your code, use these Bulletin Board Code Tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] After the last line.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-24-2011
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    19

    Re: Help with speed issues in a macro

    Thank you for the advice, Leith. I will keep that in mind for next time.

  4. #4
    Registered User
    Join Date
    01-24-2011
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    19

    Re: Help with speed issues in a macro

    I was mistaken. I don't believe I need any assistance. After some playing around, I figured out that the reason that line of code is taking so long in the macro as compared to when I do it manually is because when I do it manually, I don't use variables but rather actual numbers in the code. When I do the macro, I need to use variables to figure out what numbers to use in the formula, so it's the calculation of those variables that is taking up to 20 seconds.


    In a nutshell, when doing it manually, here is an example of what I enter (though the second number I enter is dependent upon the file I'm working on):

    =PERSONAL.XLSB!RandInt(1,400)

    But in this macro, I need it to calculate that second number itself, so I enter this:

    =PERSONAL.XLSB!RandInt(1,COUNTIFS(C[-1], RC[-1],C[6], 1))

    Thanks anyway!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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