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
Bookmarks