Code to Cut and Paste

siarrad

New Member
Joined
Nov 20, 2018
Messages
4
Hello everyone,

I'm having some trouble getting this code to do what I want. I have an excel spreadsheet with a few tabs. On sheet 1, there are record names in Column A. The names are duplicated from Sheet 1 on to Sheet 2. Sheet 2 has a table of the records and headers that outline four steps, the final step being complete. There is a button that updates the table with a colored block as the records goes through the four steps. The button opens a form that lets you select a record and then select one of the steps, to update table. When you select a record and then select the last step "complete", I want the record's row in Sheet 1 to move to next available row in Sheet 3. Currently the code copies headers from Sheet 1 to Sheet 3.


Sub MoveCells()
Dim rng As Range
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet

Set pasteSheet = Worksheets("Completed")
Set rng = Range("A1").CurrentRegion
Set rng =rng.Offset(1).Resize(rng.Rows.Count - 1)

rng.Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1,0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
If you simply want the values try this

replace
Code:
Set rng = Range("A1").CurrentRegion
    Set rng =rng.Offset(1).Resize(rng.Rows.Count - 1)
rng.Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1,0).PasteSpecial xlPasteValues

with
Code:
Set rng = ActiveCell.EntireRow
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1).EntireRow.Value = Cells(ActiveCell.Row, 1).EntireRow.Value
ActiveCell.EntireRow.Delete

To include the formatting
Code:
Set rng = ActiveCell.EntireRow
rng.Copy
With pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1)
     .PasteSpecial xlPasteFormats
     .PasteSpecial xlPasteValues
End With
ActiveCell.EntireRow.Delete
 
Last edited:
Upvote 0
Oh.. :LOL:
Just spotted that I set the range and did not use it in the code for values only
(the code works but contains a redundant line)

So either
Code:
Set rng = ActiveCell.EntireRow
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1).EntireRow.Value = Cells([COLOR=#ff0000]rng[/COLOR].Row, 1).EntireRow.Value
[COLOR=#ff0000]rng[/COLOR].EntireRow.Delete

or simply delete the redundant row
Code:
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1).EntireRow.Value = Cells(ActiveCell.Row, 1).EntireRow.Value
ActiveCell.EntireRow.Delete
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,308
Members
449,152
Latest member
PressEscape

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