Results 1 to 5 of 5

What causes a macro to run slower at certain times?

Threaded View

  1. #1
    Registered User
    Join Date
    06-20-2012
    Location
    Earth
    MS-Off Ver
    Excel 2010
    Posts
    15

    Question What causes a macro to run slower at certain times?

    I couldn't find anything that really answered this question specifically. When I run macros usually they're fast, but occasionally will run very slow. An example macro I have is pasted below. It's just a simple macro that pastes months. If I am pasting on top of a cell that contains a month it pastes the rest of the months that follow.

    Most of the time this macro runs very fast, but occasionally it takes about 1-2 seconds to run, and it is a very simple macro! It is not macro specific, as all my macros will be slow. I''m using Windows 7 with Excel 2010. I'm only using 23% of my CPU and 4.5GB of my 16GB of RAM, so I don't think it's a hardware thing.

    Is there some kind of condition that occurs that will make excel run macros slower? Any help is appreciated.

    Sub months()
        Dim monthArray(12) As String
        Dim index As Integer
        
        'I cannot believe there isn't a better way to do this
        monthArray(0) = "January"
        monthArray(1) = "February"
        monthArray(2) = "March"
        monthArray(3) = "April"
        monthArray(4) = "May"
        monthArray(5) = "June"
        monthArray(6) = "July"
        monthArray(7) = "August"
        monthArray(8) = "September"
        monthArray(9) = "October"
        monthArray(10) = "November"
        monthArray(11) = "December"
    
        If Selection.Count = 1 Then
    
            For counter = 0 To 11
                If LCase(Selection) = LCase(monthArray(counter)) Then
                    index = counter
                End If
            
            Next counter
            
            monthsLeft = 11 - index
            
            For monthCounter = 0 To monthsLeft
                ActiveCell.Offset(, monthCounter).Range("A1") = monthArray(index + monthCounter)
            Next monthCounter
            
            If LCase(Selection.Value) = "december" Then
                For monthCounter = 1 To 12
                    ActiveCell.Offset(, monthCounter).Range("A1") = monthArray(monthCounter - 1)
                Next monthCounter
            End If
                
        End If
        
    End Sub
    Last edited by Wegener; 04-02-2014 at 03:23 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macros run slow after loading another workbook, and fast if I re-open Excel?
    By Pedsdude in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-19-2013, 10:17 AM
  2. identical macros run fast and slow
    By markwattwood in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-08-2005, 04:15 PM
  3. [SOLVED] Searches slow for some Fast for others?
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 PM
  4. Searches slow for some Fast for others?
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  5. Searches slow for some Fast for others?
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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