Macro to Cut and Delete and Copy Row Content Into New Sheet

vbnew

New Member
Joined
Jul 1, 2014
Messages
1
Hi Everyone,

I am new to Macros and am working on putting some macros in place for a spreadsheet that I am creating. I basically want to be able to Cut and delete the contents of a row if a certain cell says "Yes," and move the row into the next empty row of another sheet. So far I've gotten the row to Copy and Paste, but every time I try to add the Cut and Delete functionality I get an error message. Can anyone help me with this? The Code I am using that works is below:

Sub LetterMoveYes()
'
' LetterMoveYes Macro
' Move to Letters Tab if Letter Needs to be Mailed
'
' Keyboard Shortcut: Ctrl+Shift+M
'
Dim c As Long
Dim wsD As Worksheet: Set wsD = Worksheets("Master") 'Data Worksheet.
Dim wsR As Worksheet: Set wsR = Worksheets("Letters") 'Results Worksheet
For c = 2 To 25000 'Loop through 25000 records.
With wsD.Range("AM" & c)
If .Value = "Yes" Then
wsD.Range("A" & c & ":AQ" & c & "").Copy
wsR.Activate
wsR.Range("A" & wsR.Range("A" & Rows.Count).End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End With
Next c
End Sub

I'd really appreciate if someone could help me to figure out how to modify it so that the row actually cuts and deletes (in the Master sheet) rather than just copy and pasting and remaining there.

Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello,

You could delete the row after having copied the data with the following code
Code:
Range("A" & c & ":AQ" & c & "").Delete Shift:=xlUp
OR
Code:
Rows(c).Delete Shift:=xlUp

Also you could improve some of your code i think:
Code:
wsR.Activate 'you can remove this line

               wsR.Range("A" & wsR.Range("A" & Rows.Count).End(xlUp).Row + 1).Select
               Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
                                                                             :=False, Transpose:=False
'remove the selecting to go faster through your sheet, replace the above by the following:
wsR.Range("A"  & wsR.Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial  Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
                                                                             :=False, Transpose:=False

Another question, do you actually have 25000 rows filled or is this just to be sure they are in there. If you do, you could minimize the for loop with the actual amount of rows used by counting them first.
 
Upvote 0

Forum statistics

Threads
1,223,967
Messages
6,175,673
Members
452,666
Latest member
AllexDee

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