Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy Paste Rows from one sheet to another

Posted on 2013-05-30
7
Medium Priority
?
351 Views
Last Modified: 2013-05-31
I have the code below that works, but I need for it to paste row from Sheet 16 to Sheet 19 below the last used row. And to loop through all the records on Sheet16 to end of last row to insert all onto Sheet19.

Thanks in advance.

Sub copy_cells()
     
    Dim nextrow As Long
     Sheets("cusip_tmp").Activate
     
    nextrow = Sheet16.Cells(Rows.Count, "A").End(xlUp).Row + 1
     
    Application.ScreenUpdating = False
     
    With Sheet16
        .Range("A2").Copy Sheet19.Range("A" & nextrow)
       
    End With
     
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
     
End Sub
0
Comment
Question by:leezac
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39209275
Do you truly want it pasted?  You could link the cells in Sheet 19 to those in Sheet 16.
0
 

Author Comment

by:leezac
ID: 39209288
I need it pasted as there will be other items added in the rows before this code is run.  I found this code and tried it and it works except it copies the whole row from the Manual sheet and I just need the cells from Column A.

Sub MyCopy()
    Dim lastCol As Long, lastRow As Long

    'copy from
    With Sheets("Manual")
        lastCol = .Cells(2, .Columns.Count).End(xlToLeft).column
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        .Range("A2", .Cells(lastRow, lastCol)).Copy
    End With

    'paste to
    With Sheets("Cusip_tmp")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        If lastRow = 1 And .Cells(1) = "" Then lastRow = 0
        .Cells(lastRow + 1, "A").PasteSpecial Paste:=xlPasteValues, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With

    Application.CutCopyMode = False
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39209302
Looks to me like ".Columns.Count" is giving you all the columns.  So, if you have ten columns that code will fill "lastCol" with Column J instead of column A....Count hands back a total sum of everything in it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:leezac
ID: 39209389
Ok - but how to I modify

' lastCol = .Cells(2, .Columns.Count).End(xlToLeft).column
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("A2", .Cells(lastRow, lastcol)).Copy
0
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 2000 total points
ID: 39209554
.Range("A2", .Cells(lastRow, 1)).Copy
0
 

Author Closing Comment

by:leezac
ID: 39211199
Thank you!
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39211215
Welcome :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question