+ Reply to Thread
Results 1 to 3 of 3

Why copy but not paste?

  1. #1
    Forum Contributor
    Join Date
    10-14-2004
    Location
    San Diego, CA
    Posts
    213

    Wink Why copy but not paste?

    I’m trying to copy 16 cells located in various places on sheet1.

    A1
    B6:G6, I6
    B9:H9, J9

    Paste them to the last row on sheet2.

    A1:P1

    Can this be done. If not why?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Flintstone,

    Because both sheets are in the same workbook, you don't even need to use the copy method. I am assuming the order you show on worksheet 1 is the same order used to fill the range A1 to P1 on worksheet 2. Also, I am assuming "last row" refers to the next blank row on worksheet 2. I am sure you will correct me if any of my assumptions are incorrect. I have written the code as a macro. Here is the code...


    Public Sub TransferData()

    Dim N As Long
    Dim Wks1 As Worksheet
    Dim Wks2 As Worksheet


    'Assign references to object variables
    Set Wks1 = Excel.Worksheets("Sheet1")
    Set Wks2 = Excel.Worksheets("Sheet2")

    'Find the next empty row on worksheet 2
    N = Wks2.Cells(Rows.Count, 1).End(xlUp).Row + 1

    'Directly assign cell values from worksheet to the other
    Wks2.Range("A" & N).Value = Wks1.Range("A1").Value
    Wks2.Range("B" & N &":G" & N).Value = Wks1.Range("B6:G6").Value
    Wks2.Range("H" & N).Value = Wks1.Range("I6").Value
    Wks2.Range("I" & N &":O" & N).Value = Wks1.Range("B9:H9").Value
    Wks2.Range("P" & N).Value = Wks1.Range("J9").Value

    End Sub


    Cut and paste this code into a VBA project module to use it as a macro, or cut and paste the code into your code where you need it. If you have any questions or problems, contact me via e-mail at [email protected].

    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    10-14-2004
    Location
    San Diego, CA
    Posts
    213
    Thank you for your response and the salution. It's clear I have a lot more learn.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1