copy and paste rows from one sheet to another(Excel)

Posted on 2013-06-17
Last Modified: 2013-06-17
Hi ,

I am looking for a MACRO to copy data from "sheet1" to the next available row on "sheet2".

excel sample attached.

Thanks very much
Question by:shamilaz
  • 2
  • 2
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39254752
Uncomment one of the commented rows.
The first one will copy only row 3.
The second one will copy row 3 down to the last available rows.

Sub copyrows()
Dim sws As Worksheet
Dim tws As Worksheet
Set sws = Sheets("sheet1")
Set tws = Sheets("sheet2")
'sws.Range("A3").EntireRow.Copy tws.Range("A" & Rows.Count).End(xlUp).Offset(1)
'sws.Range("A3:A" & sws.Range("A" & Rows.Count).End(xlUp).Row).EntireRow.Copy tws.Range("A" & Rows.Count).End(xlUp).Offset(1)
End Sub

Open in new window


Author Comment

ID: 39254925
Sorry forgot to mention one more thing....the copy and paste should be as a "value" that any links and formulas from the source doc will be disabled after the paste.  Appreciate if you could kindly amend to reflect this please
LVL 43

Accepted Solution

Saqib Husain, Syed earned 500 total points
ID: 39255198
Sub copyrows()
Dim sws As Worksheet
Dim tws As Worksheet
Dim sr As Range
Set sws = Sheets("sheet1")
Set tws = Sheets("sheet2")
Set sr = sws.Range("A3:A" & sws.Range("A" & Rows.Count).End(xlUp).Row)
If sws.Range("A3") <> "" Then
    tws.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize( _
        sr.Rows.Count).EntireRow.Value = sr.EntireRow.Value
End If
End Sub

Author Closing Comment

ID: 39255273
Perfect ...the macro works as expected...great....thanks very much :-)

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
First Blank Cell in a range 7 35
Problem to With line 4 41
How to add the word OR to the front of each Excel value 4 36
IF ELSE Statement in Excel Macro VBA 16 34
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
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 the scrolling table in Microsoft Excel using the INDEX function.
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…

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

17 Experts available now in Live!

Get 1:1 Help Now