Why am I getting an Error Message

mkw4949

Board Regular
Joined
Apr 28, 2006
Messages
113
For some reason that following line of code is generating an error message "PasteSpecial method of range class failed" but I dont know why. I was working before. . . Any suggestions would be helpful.

Alloc.Range("X12:EL358").PasteSpecial xlValues

Sub Compress_Values()
Dim bCalcMth As Boolean
Dim wsStrtWS As Worksheet
Dim rStrtCell As Range
Dim rCFCell As Range
Dim rLseUpCell As Range
Dim CstSprdCell As Range

Set wsStrtWS = ActiveSheet
Set rStrtCell = ActiveCell

Application.ScreenUpdating = False

If Application.Calculation = xlCalculationAutomatic Then
Application.Calculation = xlCalculationManual
bCalcMth = True
Else
bCalcMth = False
End If

LeaseUp.Activate
Set rLseUpCell = ActiveCell
LeaseUp.Range("F10:EF500").Copy
LeaseUp.Range("F10:EF500").PasteSpecial xlValues
rLseUpCell.Activate

CashFlow.Activate
Set rCFCell = ActiveCell
CashFlow.Range("G12:DU459").Copy
CashFlow.Range("G12:DU459").PasteSpecial xlValues
rCFCell.Activate
the following line of code is generating an error message for some reason. It was not doing this before. . . Anyone know what. The trouble code is


Alloc.Activate
Set rCstSprdCell = ActiveCell
Alloc.Range("X12:EL358").Copy
>>>>>>>Alloc.Range("X12:EL358").PasteSpecial xlValues<<<<<<<<
rCstSprdCell.Activate

If bCalcMth = True Then
Application.Calculation = xlCalculationAutomatic
Else
End If

wsStrtWS.Activate
rStrtCell.Activate
Application.CutCopyMode = False
Data.Range("D14") = 0

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Instead of

Code:
Alloc.Range("X12:EL358").Copy
Alloc.Range("X12:EL358").PasteSpecial xlValues

try

Code:
With Alloc.Range("X12:EL358")
    .Value = .Value
End With
 
Upvote 0
That did the trick. Thank! I have a silly question. how does the "With" statement work? You can probably tell from my code that I'm not much of a programer. I've learned by trial and error (more error really) and a couple of books. Thanks for your help.
 
Upvote 0
Anything inside a With/End with construct that is preceded with a . refers to the object that the With refers to. Clear as mud? Try clicking in the word With in the code and press F1 to get the Help on it.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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