Help with simple cut and paste macro

dvuppx

New Member
Joined
Aug 31, 2017
Messages
12
i have a document which has a lot of information in sheet1, column a right up to column BI. i would like to be able to tick a box in column BI that then removes the row from sheet 1 and puts it into sheet 2, and adds a date. this is my formula so far, but im getting stuck at the text highlighted in BOLD, as it says my subscript is out of range. i have no idea how to fix that.




Sub Cutrows()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Set WS1 = ActiveSheet
Set WS2 = Worksheets("Sheet2")


firstrow = Selection.Rows(1).Row
RowCount = Selection.Rows.Count


NEXTROW = WS9.Cells(Rows.Count, 1).And(xlUp).Row + 1


WS1.Cells(firstrow, 1).Resize(RowCount, 25).Copy Destination:=WS2.Cells(NEXTROW, 1)


WS2.Cells(NEXTROW, 26).Resize(RowCount, 1).Value = Date


WS1.Cells(firstrow, 1).Resize(RowCount, 25).Delete shift:=xlUp
End Sub
 
so sorry. okay so. i have a row of data and i would like to be able to check a box at the end that states that someone is discharged, and then for that entry to move to the other sheet (discharges) and add the date on, if possible.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
id like the last column, column BI to have a check that says Yes, or something to that effect, to say YES, id like to discharge now please. thank you for taking the time to help me.
 
Upvote 0
Right click on the tab for the sheet you want this to run on & select View Code
then paste this into the widow that opens
Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
' dvuppx

    Dim Ws As Worksheet
    
Application.EnableEvents = False

    On Error GoTo Xit
    If Target.Column <> 61 Or UCase(Target.Value) <> "YES" Then GoTo Xit
    
    Set Ws = Sheets("Discharge")
    Target.EntireRow.Copy Ws.Range("A" & Rows.Count).End(xlUp).Offset(1)
    Target.EntireRow.Delete
Xit:
Application.EnableEvents = True

End Sub
Whenever you type yes into Column BI, that row will be copied to the Discharge sheet & deleted from the original sheet
 
Upvote 0
OH my godd thank you so much! thank you thankkkk you. The only thing with that is it doesnt add a date to the end of the column when its moved over?
 
Upvote 0
The only thing with that is it doesnt add a date to the end of the column when its moved over?
:oops: oops, Forgot that bit. try this instead
Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
'' dvuppx
'
    Dim Ws As Worksheet

Application.EnableEvents = False

    On Error GoTo Xit
    If Target.Column <> 61 Or UCase(Target.Value) <> "YES" Then GoTo Xit

    Set Ws = Sheets("Discharge")
    Target.EntireRow.Copy Ws.Range("A" & Rows.Count).End(xlUp).Offset(1)
    Ws.Range("BI" & Rows.Count).End(xlUp).Offset(, 1) = Date
    Target.EntireRow.Delete
Xit:
Application.EnableEvents = True

End Sub
 
Upvote 0
thankkkkkkkkkkkkkkk youuuuuuuuuuuuuuuuuuuuu sooooooooooooooooooooooooo muchhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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