Should be a simple copy statement!

dw_73

New Member
Joined
Jun 29, 2018
Messages
9
I am having a torrid time trying to get this line of code to work when called from two different locations.
I've been through and checked that the inputs are identical from the two places, and that the "Data" page is unprotected in both cases, so I just don't understand why it is working for one and not the other.

On closer inspection it appears that the copy is actually working - I am left with values rather than formulas - but it is throwing a "Run-time error '1004': Application-defined or Object-defined error” and preventing the process from continuing for the user. If I debug and rem out the line after the error has occurred the values are there in the table.

I'm using this copy approach rather than going via the clipboard as I've been struggling with resource issues and I think this is the most efficient and quickest way to do the copy - but please make other suggestions if I'm wrong on this. Maybe I can just suppress the error message and force the process to continue?

Here's the code ...

Sheets("Data").Range(paste_range) = Sheets("Data").Range(paste_range).Value

Thanks for your help!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,
assuming paste_range is a named range then try

Code:
   With Sheets("Data").Range("paste_range")
        .Value = .Value
    End With

Dave
 
Upvote 0
Thanks Dave, I tried that but it's doing the same thing. paste_range is actually a string variable containing the range address as text (typically "$AJ$10:$BA$191794") so I dropped the quotes from your suggestion when implementing. I'm sure I should probably be using a "range" variable for this too.

Code:
'Note: row_count is passed in as a long numeric variable

Dim topcell As String
Dim bottomrightcell As String
Dim paste_range As String

topcell = Range("Data_Formulas_AbovePaste_Start").Offset(1, 0).Address()
bottomrightcell = Range("Data_Formulas_AbovePaste_Start").Offset(row_count, 17).Address()
paste_range = topcell & ":" & bottomrightcell

I originally had it constructing the paste range within the copy statement (Sheets("Data").Range(topcell & ":" & bottomrightcell).Value) and only put the paste_range variable in because it stopped working. That's the frustrating thing, it has worked ok some of the time.

Any recommendations? Could it be something to do with the size of the range being handled? Or that the dollar signs are in the reference?

Thanks, Darren
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,865
Members
449,052
Latest member
Fuddy_Duddy

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