How can I make this code run faster?

Andries

Board Regular
Joined
Feb 3, 2011
Messages
127
Hi can anyone please help in making this code run faster....it is extremely slow


Code:
Range("A:A,C:C,E:E,G:G,I:I,K:K,M:M,O:O,Q:Q,S:S,U:U,W:W,Y:Y,AA:AA,AC:AC,AE:AE,AG:AG,AI:AI,AK:AK,AM:AM,AO:AO,AQ:AQ,AS:AS,AU:AU,AW:AW,AY:AY,BA:BA,BC:BC,BE:BE,BG:BG,BI:BI,BK:BK,BM:BM,BO:BO,BQ:BQ,BS:BS,BU:BU,BW:BW,BY:BY,CA:CA,CC:CC,CE:CE").Select
Selection.ColumnWidth = 20.14
 
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("E:E").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("81:81,83:83,85:85,87:87,89:89,91:91,93:93,95:95,97:97,99:99,101:101,103:103,105:105,107:107,109:109,111:111,113:113,115:115,117:117,119:119,121:121,123:123,125:125,127:127,129:129,131:131,133:133,135:135,137:137,139:139,141:141,143:143,145:145,147:147").Select
Selection.RowHeight = 20.25
Range("CS:CS,CR:CR,CQ:CQ,CP:CP,CO:CO,CN:CN,CM:CM,CL:CL,CK:CK,CJ:CJ").Select
Selection.ColumnWidth = 20.14
 
Rows("81:81").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Rows("83:83").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Rows("85:85").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False[code]
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
selecting cells & ranges will always be slower

Code:
Rows("81:81").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
can become
Code:
with rows(81)
   .value = .value
end with
or
Code:
Range("A:A,C:C,E:E,G:G,I:I,K:K,M:M,O:O,Q:Q,S:S,U:U,W:W,Y:Y,AA:AA,AC:AC,AE:AE,AG:AG,AI:AI,AK:AK,AM:AM,AO:AO,AQ:AQ,AS:AS,AU:AU,AW :AW,AY:AY,BA:BA,BC:BC,BE:BE,BG:BG,BI:BI,BK:BK,BM:BM,BO:BO,BQ:BQ,BS:BS,BU:BU,BW:BW,BY:BY,CA:CA,CC:CC,CE:CE").Select
Selection.ColumnWidth = 20.14
can become
Code:
Range("A:A,C:C,E:E,G:G,I:I,K:K,M:M,O:O,Q:Q,S:S,U:U,W:W,Y:Y,AA:AA,AC:AC,AE:AE,AG:AG,AI:AI,AK:AK,AM:AM,AO:AO,AQ:AQ,AS:AS,AU:AU,AW :AW,AY:AY,BA:BA,BC:BC,BE:BE,BG:BG,BI:BI,BK:BK,BM:BM,BO:BO,BQ:BQ,BS:BS,BU:BU,BW:BW,BY:BY,CA:CA,CC:CC,CE:CE").ColumnWidth = 20.14
 
Upvote 0
I forgot to mention, if you make the first command of your subroutine

Code:
application.screenupdating = false
This will also speed things up, as the visual image of the sheet won't update until you're done, instead of after every paste command.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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