Excel Sleeping On PivotTableUpdate Copy Paste Formats Only

rickincanada

Board Regular
Joined
Aug 31, 2010
Messages
61
I am running the following code on PivotTableUpdate, however it is making Excel go into some strange sleep mode for about 5-6 seconds every time it runs. What I mean by this is that Excel is unresponsive however there is no hourglass.

Sub FormattingCopy(xSheet As Worksheet)
Application.ScreenUpdating = False
Dim xCell As Range
Const MaxRows = 100
For Each xCell In xSheet.Range("C5:C" & MaxRows)


xSheet.Cells(xCell.Row, xCell.Column - 1).Copy
xSheet.Cells(xCell.Row, xCell.Column).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Next xCell
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

Any help that you can provide would be GREATLY appreciated!

Thanks,
Rick
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Rick, Stepping through and selecting each cell is less efficient than referencing the entire range without Selecting it.

Try this code...
Code:
Sub FormattingCopy(xSheet As Worksheet)
    Application.ScreenUpdating = False
    Dim xCell As Range
    
    Const MaxRows = 100
    With xSheet
        .Range("B5:B" & MaxRows).Copy
        .Range("C5").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

Are you trying to format the data range of the PivotTable?
If so there are other alternatives to this approach.
 
Upvote 0

Forum statistics

Threads
1,216,031
Messages
6,128,420
Members
449,449
Latest member
Quiet_Nectarine_

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