VBA code to move row to a different sheet based on cell value

lolly150

Board Regular
Joined
Jan 9, 2010
Messages
91
Hoping some kind person can help me with some VBA code

I have a worksheet named "caseload" columns A-T
I'd like to use a VBA code to move complete rows to a new worksheet named "finished episodes" when Column A has the word either "Discharged" or "died" (which is the result of a formula in this cell)
I have one Title Row so from row 2. I'd also like to keep the destination data, so preferably not to overwrite data in the destination worksheet but add it to the end.

Please can someone help with this?

Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This could be enough. It does overwrite the rows everytime, but shouldn't be a problem since the dataset is increasing?

VBA Code:
Sub jec()
  Application.ScreenUpdating = False
  With Sheets("caseload").Cells(1).CurrentRegion
    .AutoFilter 1, Array("died", "Discharged"), 7
    .Offset(1).Resize(, 20).Copy
     Sheets("finished episodes").Range("A2").PasteSpecial xlPasteValues
    .AutoFilter
  End With
End Sub
 
Upvote 0
It does overwrite the rows everytime,

@JEC you could just make the amendment below

Rich (BB code):
Sub jec()
  Application.ScreenUpdating = False
  With Sheets("caseload").Cells(1).CurrentRegion
    .AutoFilter 1, Array("died", "Discharged"), 7
    .Offset(1).Resize(, 20).Copy
     Sheets("finished episodes").Range("A" & Rows.count).End(xlUp)(2).PasteSpecial xlPasteValues
    .AutoFilter
  End With
End Sub
 
Upvote 0
@mark, ofcourse! But if you go like this, you create duplicates every time you run this macro. ;)
 
Upvote 0
@mark, ofcourse! But if you go like this, you create duplicates every time you run this macro. ;)
True, but personally I am a bit unsure exactly what the OP is doing i.e. whether all the formulas change each time (in which case then it is a total new set of results each time and so would need appending to the bottom of the previous results each time) or if it is just the last row that is changing which would be fine with the overwrite or even a Worksheet event.
 
Upvote 0
Thank you both for your replies, apologies for late reply.

The second code worked perfectly, is there any way to delete the entry on the Caseload tab once it's been moved?
 
Upvote 0
Try (untested)...

Rich (BB code):
Sub jec3()
  Application.ScreenUpdating = False
  With Sheets("caseload").Cells(1).CurrentRegion
    .AutoFilter 1, Array("died", "Discharged"), 7
    .Offset(1).Resize(, 20).Copy
    Sheets("finished episodes").Range("A" & Rows.count).End(xlUp)(2).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    .Offset(1).EntireRow.Delete
    .AutoFilter
  End With
End Sub
 
Upvote 0
Hi Mark

If I wanted to include more than one caseload tab would that be possible?
i.e caseload 1, caseload 2, caseload 3.
Would you mind adding this to the code please
 
Upvote 0

Forum statistics

Threads
1,215,631
Messages
6,125,905
Members
449,273
Latest member
mrcsbenson

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