Macro to move entire row of the highlighted cell

wenyusa

Board Regular
Joined
Jan 16, 2009
Messages
50
Hello,

I have a sheet which I would like to create a button which will move an entire row to a different sheet in the same workbook. It should move the entire row of which the cell is highlighted.

For example: Cell A5 is selected. All of row 5 should be cut from the worksheet and pasted into a new worksheet once I click the button. If I highlight Cell B7, all of row 7 should move once I click the button.

Once I have the code, I know how to assign it to a button. I just don't know how to write the code.

I am new to macros. I can read a lot of it and do a little bit of troubleshooting but have a tough time writing my own. Any help would be greatly appreciated!

Thanks!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try

Code:
Sub test()
ActiveCell.EntireRow.Copy
Sheets.Add after:=Sheets(Sheets.Count)
Range("A1").PasteSpecial Paste:=xlPasteAll
End Sub
 
Upvote 0
This code creates a new sheet every time I run the Macro. Also, It just copys the row and requires me to hit enter for it to paste it in the new sheet. After I hit enter, I need to go back and delete the old row.

What I need is a way for it to Cut the row in the Break-Fix sheet and paste it into the Closed sheet automatically with the hit of the button.
 
Upvote 0
That makes it a bit simpler

Code:
Sub test()
ActiveCell.EntireRow.Cut Destination:=Sheets("Closed").Range("A" & Rows.Count).End(xlUp).Offset(1)
End Sub
 
Upvote 0
That is perfect! Does exactly what is necessary!

I have one extra thing to add now that I didn't think of. Is it possible to also change the color of the row. This way once you click the button, it changes the color of the row, then cuts and pastes into the closed sheet?

I want the color to be grey. Below are the RGB #s:
Red:191
Green:191
Blue:191
 
Upvote 0
Try

Code:
Sub test()
With ActiveCell.EntireRow
    .Interior.Color = RGB(191, 191, 191)
    .Cut Destination:=Sheets("Closed").Range("A" & Rows.Count).End(xlUp).Offset(1)
End With
End Sub
 
Upvote 0
If I can ask one more thing on this I would like this to work when the word "DONE" is entered in the cell run this macro and go back and delete the empty line on the first page...Can that be done?
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

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