KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 458
- Office Version
- 2016
- Platform
- Windows
Hello
Some who can help.
I have a challenge, I use this VBA code to lock sheets with by date/time in cell A1. The code is in this workbook. It works really well.
I use it to record who eats on the different days, which are from sheets 1 to 30 or 1 to 31 depending on which month you are in.
There is a CommandButton1 in each sheet so that you can manually lock and open the individual sheets.
When the VBA code locks the sheet, CommandButton1 in the applicable sheet must change from green to red and the text must change from "Open" to "Locked".
Example.
On 1 January 2024 at 12:30, sheets 2 will lock and CommandButton1 in sheets 2 must change from green to red and the text must change from "Open" to "Locked".
On January 2, 2024 at 12:30, sheets 3 will lock and CommandButton1 in sheets 3 must change from green to red and the text must change from "Open" to "Locked".
On January 3, 2024 at 12:30, sheets 4 will lock and CommandButton1 in sheets 4 must change from green to red and the text must change from "Open" to "Locked". ETC.
Any help will be appreciated
Best regards
Klaus W
Some who can help.
I have a challenge, I use this VBA code to lock sheets with by date/time in cell A1. The code is in this workbook. It works really well.
I use it to record who eats on the different days, which are from sheets 1 to 30 or 1 to 31 depending on which month you are in.
There is a CommandButton1 in each sheet so that you can manually lock and open the individual sheets.
When the VBA code locks the sheet, CommandButton1 in the applicable sheet must change from green to red and the text must change from "Open" to "Locked".
Example.
On 1 January 2024 at 12:30, sheets 2 will lock and CommandButton1 in sheets 2 must change from green to red and the text must change from "Open" to "Locked".
On January 2, 2024 at 12:30, sheets 3 will lock and CommandButton1 in sheets 3 must change from green to red and the text must change from "Open" to "Locked".
On January 3, 2024 at 12:30, sheets 4 will lock and CommandButton1 in sheets 4 must change from green to red and the text must change from "Open" to "Locked". ETC.
Any help will be appreciated
Best regards
Klaus W
VBA Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim Dato As Date
Dato = ActiveSheet.Range("A1").Value
If Not Intersect(ActiveCell, Range("C6:E6")) Is Nothing Then
If Now > Dato Then GoTo 10
Else:
End If
GoTo 20
10:
'MsgBox "Tiden er udløbet, der kan ikke indtastes i cellerne"
MsgBox "The time has expired, cannot be entered in the cells"
Range("A1").Select
Application.EnableEvents = True
'Call Laas my macro name
Exit Sub
20:
Application.EnableEvents = True
cancel = True
End Sub