VBA Maco Code Taking Long Time To Run

  • I have a macro below that’s used for converting/displaying data in a specific format. There are two triggers in the macro - it takes a specific course of action based on the value of another cell (AF1). If cell AF1 = 1 and it runs the code I have underneath that If statement, it takes a LONG TIME to run. If cell AF1 = 2 then the code runs in a reasonable amount of time.


    If I don’t touch my computer at all, it takes at least 7 minutes to run. If I have a lot of applications going or try to do something else, it nearly freezes and takes much longer (just to note, the macro still runs successfully in that case).

    Below is the code. I’m still a macro novice; is there more efficient code I can use that would produce the same results?


  • Re: Macro taking a very long time to run, possible to make it more efficient?


    try:

  • Re: Macro taking a very long time to run, possible to make it more efficient?


    Consider also;

    More tips here: Optimize Slow VBA Code

  • Re: Macro taking a very long time to run, possible to make it more efficient?


    If you use Dave's suggestion, in my code change:

    Code
    If formulaDone Then
        With .Range("D1", .Cells(.Rows.Count, "D").End(xlUp))
            .Value = .Value
        End With
    End If


    to

    Code
    If formulaDone Then
        With .Range("D1", .Cells(.Rows.Count, "D").End(xlUp))
            .Calculate
            .Value = .Value
        End With
    End If
  • Re: VBA Maco Code Taking Long Time To Run


    Thank you both for your suggestion. Dave's suggestion runs the fastest, but it seems to cause the result to output incorrectly. The value in cell AF1 is a formula, not sure if that is affected by the CalcuationManual part of the code (I'm not too familiar with that yet).


    I tried trunten's code and it's pretty quick and a HUGE improvement from my original code.


    Thanks!!!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!