Macro to Copy to Next Open Row of New Worksheet

DataMgmtAnalyst7

New Member
Joined
Dec 2, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I am running a code that copies data for a specific criteria and moves it from one worksheet to a new worksheet (Sheet2). However, I am having an issue where if I run the code a second time for new values then it deletes all the previous data from Sheet2 and copies the new data over. So, I am trying to figure out how I can edit the code so that when it paste the values to Sheet2 it always pastes them in the next available row instead of overwriting the existing data?

VBA Code:
Sub MoveCompleted()
'
'MoveCompleted Macro
'
Dim lastRow As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    ActiveSheet.Range("$A$1:$AW$" & lastRow).AutoFilter Field:=27, Criteria1:="Yes"
    Range("A1").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A1").Select
    ActiveSheet.Paste
    Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    ActiveSheet.Paste
    Sheets("EFT").Select
    Range("B2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.EntireRow.Delete
    Range("B8165").Select
    ActiveSheet.ShowAllData
    Range("B2").Select
End Sub
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub MoveCompleted()
'
'MoveCompleted Macro
'
   Dim lastRow As Long
   lastRow = Range("A" & Rows.Count).End(xlUp).Row
   With ActiveSheet
      .Range("A1:AW" & lastRow).AutoFilter 27, "Yes"
      .AutoFilter.Range.Offset(1).Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
      .AutoFilter.Range.Offset(1).EntireRow.Delete
      .ShowAllData
   End With
End Sub
 
Solution

DataMgmtAnalyst7

New Member
Joined
Dec 2, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Thank you for quick response. This code successfully solved the issue I was having.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,531
Messages
5,625,368
Members
416,096
Latest member
forevans

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top