automatically cut and paste from a table to another worksheet based on the value in a column

tbrynard01

Board Regular
Joined
Sep 20, 2017
Messages
129
Office Version
  1. 365
Platform
  1. Windows
I have a table that checks the data and if the client has discharged it puts the word discharge in column O. I would like to find a way to automatically move all the discharged clients from my active worksheet (MHRData) to another sheet called ArchiveData. Any help would be appreciated. I want the data deleted from the MHRData sheet. Thank you
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You said:
I have a table that checks the data and if the client has discharged it puts the word discharge in column O

Tell me how does this happen.
Do you manually enter discharge in column O

If not how is discharge entered in column O

And do you want this row removed from the sheet named:
MHRData
 
Upvote 0
I use a formula that checks a census worksheet and puts discharged if the client is no longer on census

Yes I want this row removed from the MHRData sheet.

Thanks
 
Upvote 0
I use a formula that checks a census worksheet and puts discharged if the client is no longer on census

Yes I want this row removed from the MHRData sheet.

Thanks
I can write a script to do this but you said:
find a way to automatically move all the....

Something has to occur for this script to run.

Like you may need to click a button or double click a cell or manually do something.

A Excel script in most cases cannot just run automatically.

So would clicking a button work for you?

You click a Button to run the script and all rows with "
discharged" in column O will be copied to other sheet and rows from original sheet are deleted. Would that work for you?
 
Upvote 0
Try putting this script in a button on the current sheet with your data.

See below post for code:
 
Last edited:
Upvote 0
VBA Code:
Sub Filter_Me_Please()
'Modified  11/18/2019  9:44:20 PM  EST
Application.ScreenUpdating = False
Dim lastrow As Long
Dim lastrowa As Long
Dim c As Long
Dim s As Variant
c = 15 ' Column Number Modify this to your need
s = "discharged" 'Search Value Modify to your need
lastrow = Cells(Rows.Count, c).End(xlUp).Row
lastrowa = Sheets("MHRData").Cells(Rows.Count, c).End(xlUp).Row + 1

With ActiveSheet.Cells(1, c).Resize(lastrow)
    .AutoFilter 1, s
    counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("MHRData").Rows(lastrowa)
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi, I was finally able to work on this and I'm getting the error message "no value found" but I have several rows with "Discharged" in that column.

Also don't see where it's pasting it in the ArchiveData sheet?

This is the code I put in the Command button - I'm sure I'm missing something basic:

Private Sub CommandButton1_Click()

Application.ScreenUpdating = False
Dim lastrow As Long
Dim lastrowa As Long
Dim c As Long
Dim s As Variant
c = 15
s = "Discharged"
lastrow = Cells(Rows.Count, c).End(xlUp).Row
lastrowa = Sheets("MHRData").Cells(Rows.Count, c).End(xlUp).Row + 1

With ActiveSheet.Cells(1, c).Resize(lastrow)
.AutoFilter 1, s
counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
If counter > 1 Then
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("MHRData").Rows(lastrowa)
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete

Else
MsgBox "No values found"
End If
.AutoFilter
End With
Application.ScreenUpdating = True
End Sub

Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

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