Solved

Copy Paste Rows from one sheet to another

Posted on 2013-05-30
7
311 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

910 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

22 Experts available now in Live!

Get 1:1 Help Now