user2242660
user2242660

Reputation: 35

Need to optimize a slow vba code

I am using following code and it is taking forever to complete-

For i = 1 To 21408
    Range("abcd").Copy
    Rows(Range("abcd").Offset(i, 0).Row).Insert Shift:=xlDown
    Application.CutCopyMode = False
Next i

abcd is Named Range having 8 fields.

Can someone please suggest a way to optimize this code or re-write in a way to achieve the same output?

Thanks

Upvotes: 1

Views: 109

Answers (1)

Doug Glancy
Doug Glancy

Reputation: 27478

This does the same thing, much faster:

With Range("abcd")
    .Copy
    .Offset(1).Resize(21408, .Columns.Count).Insert Shift:=xlDown
    Application.CutCopyMode = False
End With

Upvotes: 3

Related Questions