Autodelete a row from protected sheet and move to another protected sheet based on date

SaraWitch

Active Member
Joined
Sep 29, 2015
Messages
378
Office Version
  1. 365
Platform
  1. Windows
Hello peeps,

In a protected sheet ("Placements"), I have a formula in column U that calculates a date from a range of other cells. When a date is populated, I want the row to automatically delete and paste into another protected sheet ("Leavers"). I think I'm almost there with the formula below but know I have to change the <> in line 4 (I've tried some date text but it doesn't work).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect ("password")
    Dim NextRow As Long
    If Target.Column <> 21 Then Exit Sub
    Application.EnableEvents = False
    With Sheets("Leavers")
        NextRow = .Cells(Rows.Count, 8).End(xlUp).Row + 1
        Target.EntireRow.Copy Destination:=.Cells(NextRow, 1)
        Target.EntireRow.Delete
    End With
    Application.EnableEvents = True
ActiveSheet.Protect ("password")
End Sub

Any help would be gratefully received :)
 
If you are working with protected sheets, you will need to first unprotect them in order to make any edits to them. You can do that at the beginning of your VBA code.
See here: https://www.wallstreetmojo.com/vba-unprotect-sheet/

You can then re-protect the code at the end of your VBA code after the changes have been made.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If the text is "x" then try this:

Libro1
CDEFGHIJKLM
3DateNameDepartmentWhere PurchasedHi Visibility ShirtQuantity RemainingLong TrousersQuantity Remaining25 in 1 Jacket Soft ShellQuantity Remaining3
403/07/2023Name01DepotThe Uniform Zone5x511
503/07/2023Name02DepotThe Uniform Zone551x
604/07/2023Name03DepotThe Uniform Zone5x232
704/07/2023Name03DepotThe Uniform Zone5x52
805/07/2023Name04DepotThe Uniform Zone5232
915/07/2023Name05DepotThe Uniform Zone551
10
11
12
13
14DateNameDepartmentWhere PurchasedHi Visibility ShirtQuantity RemainingLong TrousersQuantity Remaining25 in 1 Jacket Soft ShellQuantity Remaining3
1503/07/2023Name01DepotThe Uniform Zone5x50110
1603/07/2023Name02DepotThe Uniform Zone050510x
1704/07/2023Name03DepotThe Uniform Zone5x23002
1804/07/2023Name03DepotThe Uniform Zone5x50002
Hoja1
Cell Formulas
RangeFormula
C14:M18C14=LET(t, "x", IFERROR(VSTACK(Hoja1!$C$3:$M$3,FILTER(Hoja1!$C$4:$M$9,(Hoja1!$H$4:$H$9=t)+(Hoja1!$J$4:$J$9=t)+(Hoja1!$M$4:$M$9=t))),C3:M3) )
Dynamic array formulas.
 
Upvote 0
Thank you, and what would the workbook VBA that @MARK858 gave look like instead of 0:
VBA Code:
Sub Filterit()
    Application.ScreenUpdating = False
  
    With Sheets("Current").Range("G2:G" & Sheets("Current").Range("G" & Rows.Count).End(xlUp).Row)
  
        .AutoFilter 1, 0
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy _
        Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
      
    End With
     
    Application.ScreenUpdating = True
End Sub

I have tried "Left" which will be my trigger word but this isn't working:
VBA Code:
Sub Filterit()
    Application.ScreenUpdating = False
  
    With Sheets("Current").Range("G2:G" & Sheets("Current").Range("G" & Rows.Count).End(xlUp).Row)
  
        .AutoFilter 1, "Left"
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Copy _
        Sheets("Exceeded").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter
      
    End With
     
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you, @Joe4.

I have tried several VBAs but am getting nothing to work.

If okay, I may post on another forum... Is this okay with the rules?
 
Upvote 0
Thank you, @Joe4.

I have tried several VBAs but am getting nothing to work.

If okay, I may post on another forum... Is this okay with the rules?
It is fine, as long as you mention you are doing so and post a link to the other posts, as outlined in rule 13 here: Message Board Rules
 
Upvote 0
Yes - "Left" and "Due" are returning based on a formula calculating from previous cell's date. And I need to move the row from one protected sheet to another protected one if the formula value is "Left".

Just for transparency I have already posted my query under the heading, "Autodelete a row from protected sheet and move to another protected sheet based on date" but have not yet found a solution. I have asked if okay to post on another forum, but before I do, I came across this thread...🤞
 
Upvote 0
If it is only Left in the cell what you done should work if there is no space in front of the Left, you can also try "=Left".
I am not in to test but I'll have a look back when I get in this evening.

As for posting on other forums it is ok as long as you paste a link in the question you asked to the post in the other forum so people don't duplicate their responses.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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