Shorten Excel Paste Special Formula

redbaron06

New Member
Joined
Aug 6, 2010
Messages
44
Hi All,

Does anyone have any idea how I can optimize this script? I could really use your help since this keeps freezing my computer. Thanks in advance!!

Code:
Sub WriteCountryData()
Application.ScreenUpdating = False
 
Range("U2").Copy
Range("T45:T545").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U3").Copy
Range("T546:T1046").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U4").Copy
Range("T1047:T1547").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U5").Copy
Range("T1548:T2048").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U6").Copy
Range("T2049:T2549").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U7").Copy
Range("T2550:T3050").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U8").Copy
Range("T3051:T3551").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U9").Copy
Range("T3552:T4052").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U10").Copy
Range("T4053:T4553").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U11").Copy
Range("T4554:T5054").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U12").Copy
Range("T5055:T5555").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U13").Copy
Range("T5556:T6056").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U14").Copy
Range("T6057:T6557").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U15").Copy
Range("T6558:T7058").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U16").Copy
Range("T7059:T7559").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U17").Copy
Range("T7560:T8060").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U18").Copy
Range("T8061:T8561").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U19").Copy
Range("T8562:T9062").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U20").Copy
Range("T9063:T9563").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U21").Copy
Range("T9564:T10064").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U22").Copy
Range("T10065:T10565").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U23").Copy
Range("T10566:T11066").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U24").Copy
Range("T11067:T11567").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U25").Copy
Range("T11568:T12068").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U26").Copy
Range("T12069:T12569").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U27").Copy
Range("T12570:T13070").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U28").Copy
Range("T13071:T13571").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U29").Copy
Range("T13572:T14072").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U30").Copy
Range("T14073:T14573").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U31").Copy
Range("T14574:T15074").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U32").Copy
Range("T15075:T15575").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U33").Copy
Range("T15576:T16076").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U34").Copy
Range("T16077:T16577").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U35").Copy
Range("T16578:T17078").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U36").Copy
Range("T17079:T17579").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U37").Copy
Range("T17580:T18080").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U38").Copy
Range("T18081:T18581").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U39").Copy
Range("T18582:T19082").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U40").Copy
Range("T19083:T19583").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U41").Copy
Range("T19584:T20084").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U42").Copy
Range("T20085:T20585").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U43").Copy
Range("T20586:T21086").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U44").Copy
Range("T21087:T21587").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U45").Copy
Range("T21588:T22088").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U46").Copy
Range("T22089:T22589").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U47").Copy
Range("T22590:T23090").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U48").Copy
Range("T23091:T23591").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U49").Copy
Range("T23592:T24092").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U50").Copy
Range("T24093:T24593").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U51").Copy
Range("T24594:T25094").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U52").Copy
Range("T25095:T25595").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U53").Copy
Range("T25596:T26096").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U54").Copy
Range("T26097:T26597").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U55").Copy
Range("T26598:T27098").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Range("U56").Copy
Range("T27099:T27599").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U57").Copy
Range("T27600:T28100").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U58").Copy
Range("T28101:T28601").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U59").Copy
Range("T28602:T29102").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U60").Copy
Range("T29103:T29603").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U61").Copy
Range("T29604:T30104").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U62").Copy
Range("T30105:T30605").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U63").Copy
Range("T30606:T31106").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U64").Copy
Range("T31107:T31607").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U65").Copy
Range("T31608:T32108").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U66").Copy
Range("T32109:T32609").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U67").Copy
Range("T32610:T33110").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U68").Copy
Range("T33111:T33611").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U69").Copy
Range("T33612:T34112").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("Q70").Copy
Range("T34113:T34613").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U71").Copy
Range("T34614:T35114").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U72").Copy
Range("T35115:T35615").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Range("U73").Copy
Range("T35616:T36116").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Application.ScreenUpdating = True 
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try turning off calculation as well as screenupdating...

Application.Calculation = xlCalculationManual

Turn back on at the end
Application.Calculation = xlCalculationAutomatic
 
Upvote 0
And this won't necessarily make it any faster, but certainly easier on the eyes...

Code:
Sub WriteCountryData()
Dim C As Range, PrevCalc As Variant
With Application
    .ScreenUpdating = False
    PrevCalc = .Calculation
    .Calculation = xlCalculationManual
End With

Range("U2").Copy
Range("T45:T545").PasteSpecial Paste:=xlPasteValues
For Each C In Range("U3:U73")
    C.Copy
    Cells(Rows.Count, "T").End(xlUp).Offset(1,0).Resize(501,1).PaseSpecial Paste:=xlPasteValues
Next C

With Application
    .ScreenUpdating = True
    .Calculation = PrevCalc
End With
End Sub


Hope that helps.
 
Upvote 0
This is 1000x faster. Just a small correction for others reference. Your the best jonmo1!!

Cells(Rows.Count, "T").End(xlUp).Offset(1,0).Resize(501,1).PasteSpecial

SOLVED

And this won't necessarily make it any faster, but certainly easier on the eyes...

Code:
Sub WriteCountryData()
Dim C As Range, PrevCalc As Variant
With Application
    .ScreenUpdating = False
    PrevCalc = .Calculation
    .Calculation = xlCalculationManual
End With
 
Range("U2").Copy
Range("T45:T545").PasteSpecial Paste:=xlPasteValues
For Each C In Range("U3:U73")
    C.Copy
    Cells(Rows.Count, "T").End(xlUp).Offset(1,0).Resize(501,1).PaseSpecial Paste:=xlPasteValues
Next C
 
With Application
    .ScreenUpdating = True
    .Calculation = PrevCalc
End With
End Sub


Hope that helps.
 
Upvote 0
Glad to help, thanks for the feedback..

Good catch on the typo....dang keyboard gremlins..
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

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