Slow VBA - Need Help Speeding it Up

Bkisley

Board Regular
Joined
Jan 5, 2017
Messages
100
Below is my current code. It works exactly as I need after a ton of different changes I have made. The issue is...the code takes like 30 seconds to run. It is not a dealbreaker however it is not very efficient. Any ideas on how I can speed this up??

VBA Code:
Sub CreateInvoice()
    Range("A11:u500").Select
    Selection.Copy
    Range("B12").Select
    Selection.End(xlDown).Select
    Sheets("Invoice").Select
    Range("z9").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Rows("10:514").EntireRow.AutoFit

Dim c As Range

    For Each c In Range("A10:A510").Cells
        If c.Value = "True" Then
            c.EntireRow.Hidden = True

        End If
    Next c
    
    Range("AA1:AL1").Select
    Selection.Copy
    Sheets("Invoice History").Select
    Range("B4").Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

    Sheets("Invoice").Select
    
    Range("B2:D6").Select
    
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Using Select and Selection is a good way to slow things down, as such, removing them will speed it up.

I've tried to keep this in line with what your code looks like it is doing but it is untested.
VBA Code:
Sub CreateInvoice()
With Application
    .EnableEvents = False
    .ScreenUpdating = False
    .Calculation = xlManual
End With
    Range("A11:U500").Copy
With Sheets("Invoice")
    .Range("z9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    .Rows("10:514").EntireRow.AutoFit

        Dim c As Range
    For Each c In .Range("A10:A510").Cells
        If c.Value = "True" Then
            c.EntireRow.Hidden = True
        End If
    Next c
    .Range("AA1:AL1").Copy
End With
With Sheets("Invoice History")
    .Range("B4").End(xlDown).End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End With
With Application
    .EnableEvents = True
    .ScreenUpdating = True
    .Calculation = xlAutomatic
End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top