Overflow error when using range object

renuvish

New Member
Joined
Aug 2, 2014
Messages
4
hi,
I am trying to copy data from cells A2to U305 of worksheet 1 to worksheet 2 , in the same workbook using range object. I seem to be getting overflow error and i am unable to find out the problem. Request some help in finding the issue in my code

Sub CopyData()
Dim SourceRange As Range
Dim DestRange As Range

Set SourceRange = ThisWorkbook.Worksheets(2).Range("A2:U305")
Set DestRange = ThisWorkbook.Worksheets(3).Range("A2:U305")
Set DestRange = DestRange.Resize(SourceRange.Rows.Count, _
SourceRange.Columns.Count)

DestRange.Value = SourceRange.Value

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
It works fine for me.

Which line is highlighted when you get the error?

The Resize line isn't necessary, since you already have the DestRange set to the same dimensions as the SourceRange.
 
Upvote 0
Why not

Code:
Sub CopyData()
ThisWorkbook.Worksheets(2).Range("A2:U305").Copy
ThisWorkbook.Worksheets(3).Range("A2").PasteSpecial Paste:=xlPasteValues
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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