PDA

View Full Version : Copy between sheets



copyt
07-19-2012, 06:28 AM
Hello all,

I need to set a range to copy data in between sheets

I have tried

set rng = Sheets(1).Range("A" & i ":D" & j)
set rng2 = Sheets(2).Range("A" & i ":D" & j)

rng.copy rng
and

set rng = sheets(1).range(cells(i,1),cells(j,4))
set rng2 = sheets(2).range(cells(i,1),cells(j,4))

rng.copy rng

but none of them works

any help would be appreciated, thanks

CodeNinja
07-19-2012, 06:33 AM
copyt,
Looks good to me (only thing i see is range.copy rng should be just rng.copy)

This works for me:

Sub test()
Dim rng As Range
Dim i As Integer
Dim j As Integer

i = 1
j = 10

Set rng = Sheets(1).Range("D" & i & ":D" & j)
rng.Copy

Sheet1.Cells(1, 5).Select
ActiveCell.PasteSpecial


End Sub

copyt
07-19-2012, 10:58 AM
@ CodeNinja (http://www.vbaexpress.com/forum/member.php?u=45463) Thank you very much. Your code also works for me. :bow::bow:

Teeroy
07-22-2012, 12:51 AM
Hi Copyt,

I hate to be the bearer of bad news, and you're going to kick yourself, but your code actually worked. The code
rng.copy rng
will copy the range onto itself. All you needed was to add a "2" to get
rng.copy rng2

Life's like that. :banghead: