Delete data in selected cells of a filtered range

sparky2205

Well-known Member
Joined
Feb 6, 2013
Messages
507
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
HI folks,
I have a protected spreadsheet which has every second row editable.
At the end of the year I want to be able to delete all of the information from the editable rows of the sheet.
When I filter on the editable rows, select all and press delete, I get the error telling me the sheet is protected.
I am selecting by highlighting the first cell then control and click to the last cell.
I assume this is because when I select the filtered cells the delete is looking through the filter and also attempting to delete the information in the protected cells.

Is there any way to achieve this manually? It is too risky to provide a button linked to VBA. Someone will accidentally delete information half way through the year.

Thanks.

Additional info:
I do not have the option of manually unprotecting the sheet to perform the deletion.
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi Peter,
thanks for the response.
If I'm reading your message correctly I should:

Apply my filter
F5 -> Special to select visible cells only
Delete the selected cells.


Two problems:
I am only deleting the contents of certain cells within the filtered rows. And there are locked cells with data I don't want to delete in other columns of the same rows. My apologies, I should have made that clear.
But regardless, the Special option in Go To doesn't appear to work on a protected sheet. At least it's greyed out on my sheet.
 
Upvote 0
Is there any way to achieve this manually? It is too risky to provide a button linked to VBA. Someone will accidentally delete information half way through the year.
If a user might use vba to delete the data at the wrong time, surely they could also use the manual method to delete the data at the wrong time?

Could you consider a macro that had a safety mechanism? For example ..
- The macro might first ask for a password (which you know but the other users don't) before doing the deletions.
- The macro might prevent deletions unless the current date is between 5th August and 12th August.
etc
 
Upvote 0
Good morning Peter,
you are right of course, a user could delete the data manually. But to do this they would have to filter the data and delete it row by row. This would have to be a very deliberate action.
What I'm worried about is someone being able to press a button accidentally and delete all the data.
Of course I could have a warning message telling the user they are about to delete all the data but this is an important file and I don't want to be responsible for giving them that option.
The data deletion activity will only be carried out once a year when the file for the next year is being prepared so I'm just going to have them complete that task manually. This can be achieved without having to unprotect the spreadsheet which is my ultimate aim as the spreadsheet will be validated.
I do like your idea of the protected macro though. I'll play around with that when I get some time, just to see if I can get it to work.

Thanks for your help Peter.
Have a good day, or night, as it is with you.
 
Upvote 0
I do like your idea of the protected macro though. I'll play around with that when I get some time, just to see if I can get it to work.
I don't know when your year ends or just when you would want to allow the deletions but this is what I had in mind. It would only allow deletions in the period 5th to 12th August, and only if the user confirmed the action.

Code:
Sub Clear_Data()
  Dim Resp As VbMsgBoxResult
  
  If Month(Date) = 8 And Day(Date) >= 5 And Day(Date) <= 12 Then
    Resp = MsgBox("Are you sure you want to delete data?", vbYesNoCancel)
    If Resp = vbYes Then
      'Code here to do the deletion
    Else
      MsgBox "OK, no deletions"
    End If
  Else
    MsgBox "Unable to delete at this time"
  End If
End Sub


... but this is an important file ..
So there would be backups if something did happen to go wrong?
 
Last edited:
Upvote 0
Yes, there would be a backup. The file is a network file so the usual daily backup would apply. At a max 24 hours of data would be lost.
But this is not a file that changes every hour, nor even every day. And changes to the file are driven by controlled documents. It would be easy to restore any lost data.
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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