Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy Paste Rows from one sheet to another

Posted on 2013-05-30
7
Medium Priority
?
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

704 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