Time locking sheet

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Good Day Everyone!

I have a workbook with multiple worksheets.

Upon a worksheet, I have a private sub that runs the following code and locks the sheet based upon an expire date.

VBA Code:
Sub Macro26()
'
'Time Lock Macro
'Worksheets(2).Activate

    With ThisWorkbook.Worksheets(2)
    
Select Case True

  Case Not IsEmpty(Sheet1.Range("D3").Value)

            If Date > (.Range("D3") + 9) Then
                                        '1 = 1 whole day after Sheet1.D3
                                        '2 = 2 whole days after Sheet1.D3
                    
            Call YOUSUBLOCK_1
            
            MsgBox "Your sheet has expired and has been protected!", vbInformation

            End If
            
    Exit Sub
  
       
  Case IsEmpty(Sheet1.Range("D3").Value)

Exit Sub


End Select
    
    End With
 
End Sub

It works well but I notice a flaw upon the sheet; only after it is executed.

When you switch from one worksheet tab to the next worksheet tab; the code seems to become undone.

Where the user can access any cell upon the "locked" sheet and even type in a cell.

Do you know of a way to prevent the cursor from accessing a cell upon the "locked" sheet?

Or is there a way to prevent the user to selecting the other worksheets tabs without hiding the sheet tabs?

Or do you have any other suggestions?


Thank you,
Pinaceous
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
i see nowhere that the sheet is protected and which cells in that sheet are locked. (YOUSUBLOCK_1 ???)
You can also use the scrollarea.
If you use a row for that one, you can use the arrows LEFT and RIGHT to move sidewards and the mousewheel to go UP DOWN
VBA Code:
Sub MyScrollarea()
     Sheets("MySheet").ScrollArea = Rows(35).Address            'row 35 is an unimportant, unused row
End Sub
 
Upvote 0
excel isn't good protected, thus even that scrollarea is easy to override
in the ribbon, Developpers>properties>scrollarea --> delete the content behind "scrollarea"
 

Attachments

  • Schermafbeelding 2022-02-13 022939.png
    Schermafbeelding 2022-02-13 022939.png
    52.3 KB · Views: 7
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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