Lock cells in a column after day end

jgopal

New Member
Joined
Dec 27, 2020
Messages
23
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
Hello Friends,

I am trying to make a report tracking spreadsheet. The workbook currently contains a Daily Dashboard (which is working fine thanks to help from Dominic) and the 12 months of the year. Every month worksheet is the same and has a list of reports, with target time that the report has to be sent with all days of the month. User updates the time he/she sends the report daily. The daily dashboard is dynamic capturing the daily input of the user for the Manager to see the status of the current day.

Now, to ensure control on the data entry, we want to lock all the time input cells of the day at end of day which is 00:00 hrs of the following day. Basically, input column under 11/04/2022 should get locked when it is opened on 12/04/2022. I found a few macros when I searched but nothing specifically for my application, hence I believe it can be done. I probably will have to apply it to all 12 worksheets manually by changing the sheet name.

If the xl2bb capture is working, you all will be able to see that all cells except the time input cells are locked for the data entry.
Hope my requirement is clear and you guys can help us with this. If not, please let me know and I will try to explain further.

It looks like everyday there are new requirements coming up, which I will post as separate threads if I am unable to find a solution online. Looks like this project is going to end up being a software. So appreciate all your help and knowledge in such advanced excel solutions.

Thanks
Best Regards
J



Report Tracker.xlsm
ABCDEFGHIJKLMNOPQR
3DAYFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturday
4CODETIME01020304050607080910111213141516
5D1-111:30WEEKEND13:00WEEKEND
6D1-211:3012:00
7D1-2111:3011:00
8D1-2211:3011:35
9D1-311:3012:01
10D1-415:00
11D1-515:00
12D1-611:30
13D2-19:30
14D2-29:30
15D2-312:00
16D3-115:00
17W1-1
18W1-211:30
19W1-311:30
20W1-411:30
21W1-511:30
22W1-611:30
23W2-1
24W2-211:30
25W2-311:30
26W2-411:30
27W2-511:30
28W3-1
29W3-214:00
30W3-314:00
31U1-1
32U1-2
33U1-317:00
34U1-417:00
35U1-57:12
36U1-6
37U1-7
38U1-8
39U1-9
April
Cell Formulas
RangeFormula
C3:R3C3=TEXT(C4,"dddd")
 

Attachments

  • Report tracker.png
    Report tracker.png
    157.1 KB · Views: 20

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Start by unlocking all the cells in all 12 sheets. Place this macro in the code module for ThisWorkbook. Do the following: Hold down the ALT key and press the F11 key. This will open the Visual Basic Editor. In the left hand pane, double click on "ThisWorkbook". Copy/paste the macro into the empty window that opens up. Close the window to return to your sheet. Save the workbook as a macro-enabled file. This macro will run automatically when you open the file and will lock the cells in all worksheets. In order to lock the cells, the macro will need protect all 12 sheets. As currently written, the macro does not use a password to do the protection. If you want to use a password, please let me know. If there are any sheets that need to be excluded, please post those sheet names.
VBA Code:
Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim foundDate As Range, ws As Worksheet
    For Each ws In Sheets
        ws.Unprotect
        Set foundDate = ws.Rows(4).Find(Date, LookIn:=xlFormulas, lookat:=xlWhole)
        If foundDate.Offset(-1, -1) = "Sunday" Then
            ws.Columns(foundDate.Column - 2).Locked = True
        Else
            ws.Columns(foundDate.Column - 1).Locked = True
        End If
        With ws
            .Protect
            .EnableSelection = xlUnlockedCells
        End With
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps,

I haven't tested your macro code yet as I do have one other worksheets and probably will have more worksheets that will extract data from these 12 months (please see the attached screen grab which shows the other two sheets. Currently, there is Daily Dashboard sheet which populates the current day's status of the daily reports being sent.

There will be a Weekly Dashboard or maybe Weekly Report sheet that I have to start work on too which will have the same columns like code, tartget time and 6 columns for time values extracted from the month sheets based on a date range which would typically but not limited to the 6 days of the past week. I say not limited because at any given time, if the team lead wishes to view the report for a another week, it should be able to do that too. Then there might be a quarterly report as I expect more new requirements as this excel workbook turns into a 'software'.

As for passwords for worksheet protection, yes, all worksheets will be protected with the same password to avoid any accidental changes or deletions in formulas, formatting, etc.

Thanks
Regards
J
 
Upvote 0
Hi again,
I tried the above and am getting the following error when I open the workbook
I had another macro already running to activate the Daily Dashboard worksheet when the workbook opens like below:

Private Sub Workbook_Open()

Worksheets("Daily Dashboard").Activate

End Sub

I thought this could be the cause of the error, so I removed that completely to see what is the result of your code.

Please let me know if I am doing anything wrong.

Regards
J
 

Attachments

  • Screen Shot 2022-04-11 at 13.57.29.png
    Screen Shot 2022-04-11 at 13.57.29.png
    28.3 KB · Views: 18
  • Screen Shot 2022-04-11 at 13.57.40.png
    Screen Shot 2022-04-11 at 13.57.40.png
    68.3 KB · Views: 21
Upvote 0
I tested the macro using the data you posted in your original post and it worked properly. Try this revised version:
VBA Code:
Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim foundDate As Range, ws As Worksheet
    Sheets("Daily Dashboard").Activate
    For Each ws In Sheets
        If ws.Name <> "Daily Dashboard" Then
            ws.Unprotect
            Set foundDate = ws.Rows(4).Find(Date, LookIn:=xlFormulas, lookat:=xlWhole)
            If foundDate.Offset(-1, -1) = "Sunday" Then
                ws.Columns(foundDate.Column - 2).Locked = True
            Else
                ws.Columns(foundDate.Column - 1).Locked = True
            End If
            With ws
                .Protect
                .EnableSelection = xlUnlockedCells
            End With
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
If it still doesn't work, perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here (de-sensitized if necessary).
 
Upvote 0
I tested the macro using the data you posted in your original post and it worked properly. Try this revised version:
VBA Code:
Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim foundDate As Range, ws As Worksheet
    Sheets("Daily Dashboard").Activate
    For Each ws In Sheets
        If ws.Name <> "Daily Dashboard" Then
            ws.Unprotect
            Set foundDate = ws.Rows(4).Find(Date, LookIn:=xlFormulas, lookat:=xlWhole)
            If foundDate.Offset(-1, -1) = "Sunday" Then
                ws.Columns(foundDate.Column - 2).Locked = True
            Else
                ws.Columns(foundDate.Column - 1).Locked = True
            End If
            With ws
                .Protect
                .EnableSelection = xlUnlockedCells
            End With
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
If it still doesn't work, perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here (de-sensitized if necessary).
Thank you. let me try it it and I will let you know.
If it doesn't work or throws some error, I will upload and share the link. Nothing to de-sensitize!!!
 
Upvote 0
Hi

Tried it but gave me the error. I am sharing the file on Dropbox for you to check.
Also attaching the pic of the error.


1. We don't want the users to changes the formatting, text changes in the titles or target time cells. Hence all worksheets require to be password protected allowing the users to enter only the time in the current day's cell of every month against the report that is complete and sent. So is it necessary that all cells of the 12 month sheets are unlocked or is there a way around that?

2. Daily Dashboard is locked and its only for viewing by the Manager to see the status.

3. Weekly report will be locked except for input of start date. Team leader will use this to send the report status of the week.

Thanks
Regards
J
 

Attachments

  • Screen Shot 2022-04-12 at 15.58.33.png
    Screen Shot 2022-04-12 at 15.58.33.png
    76.7 KB · Views: 13
Upvote 0
Start by protecting all your monthly sheets. Then use this macro in the code module for ThisWorkbook. Change the password (in red) to suit your needs. Save the file, close it and re-open it. The macro will lock all cells in the sheet for the current month except for the cells for the current date, starting in row 5.
Rich (BB code):
Private Sub Workbook_Open()
    Application.ScreenUpdating = False
    Dim foundDate As Range, ws As Worksheet, mon As String, lRow As Long
    mon = MonthName(Month(Date))
    Sheets("Daily Dashboard").Activate
    With Sheets(mon)
        .Unprotect Password:="MyPassword"
        lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Set foundDate = .Rows(4).Find(Date, LookIn:=xlFormulas, lookat:=xlWhole)
        .Cells.Locked = True
        .Cells(5, foundDate.Column).Resize(lRow - 4).Locked = False
        .Protect Password:="MyPassword"
        .EnableSelection = xlUnlockedCells
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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