How to Paste a Row to the Next Empty Row on Another Sheet

jei13jei

New Member
Joined
Jan 3, 2018
Messages
2
Hello,

I have created file wherein the button will auto transfer the row from Customer tab (sheet1) to Closed tab (sheet2) when the CLOSE sign is indicated in col K (a.k.a auto transfer when criteria is met). It is already doing the functions that I wan it to do, except for 2 last functions:

1: auto-transfer the whole row (row A:K) from Customer tab to Close tab if col K is marked as CLOSE.
2: erase the details in the row when it's already copied to Close tab

*Missing functions:
3: Paste the CLOSE row details from Customer tab to the Next Empty row on Close tab
4: auto-delete/auto-shift Cells UP when the row in Customer tab is empty (optional)

===Existing code===
Private Sub CommandButton1_Click()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet

Set Source = ActiveWorkbook.Worksheets("Customer")
Set Target = ActiveWorkbook.Worksheets("Closed")

j = 1

For Each c In Source.Range("K1:K500")
If c = "CLOSE" Then
Source.Rows(c.Row).Copy Target.Rows(j)
Source.Rows(c.Row).ClearContents
End If
Next c

End Sub
=====
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hello jei13jei,

Try the following code updated to use autofilter and a dynamic Column K:-
Code:
Private Sub CommandButton1_Click()

Dim ws As Worksheet
Dim ws1 As Worksheet

Set ws = Worksheets("Customer")
Set ws1 = Worksheets("Closed")

Application.ScreenUpdating = False

With ws.[A1].CurrentRegion
             .AutoFilter 11, "CLOSE"
             .Offset(1).EntireRow.Copy
             ws1.Range("A" & Rows.Count).End(3)(2).PasteSpecial xlValues
             .Offset(1).EntireRow.Delete
             .AutoFilter
End With
             
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
You're welcome jei13jei. I'm glad that I was able to help.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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
Back
Top