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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

732 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