Consulting

Results 1 to 4 of 4

Thread: Copy between sheets

  1. #1

    Copy between sheets

    Hello all,

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

    I have tried

    [vba]set rng = Sheets(1).Range("A" & i "" & j)
    set rng2 = Sheets(2).Range("A" & i "" & j)

    rng.copy rng[/vba]
    and

    [vba]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[/vba]

    but none of them works

    any help would be appreciated, thanks

  2. #2
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    copyt,
    Looks good to me (only thing i see is range.copy rng should be just rng.copy)

    This works for me:

    [VBA]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 & "" & j)
    rng.Copy

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


    End Sub[/VBA]

  3. #3
    @ CodeNinja Thank you very much. Your code also works for me.

  4. #4
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    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
    [VBA]rng.copy rng [/VBA]
    will copy the range onto itself. All you needed was to add a "2" to get
    [VBA]rng.copy rng2 [/VBA]

    Life's like that.
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •