Solved

Copy Paste Rows from one sheet to another

Posted on 2013-05-30
7
299 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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 500 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now