Automatically lock cells when a date has passed

daveed

New Member
Joined
Dec 20, 2005
Messages
1
I just found this site and the questions and answers are great! Here is mine – we are using a spreadsheet to load financial data into an accounting package. Users in different countries will enter their balance sheet and income statement figures into their own version of a spreadsheet. The activity is referenced on a different page and formatted in “flat file” version that will allow the upload. We don’t want to allow the users to change activity that has already been loaded.
To be more clear, there are 12 columns – one for each month – under which data is entered for various accounts on the rows. The spreadsheet calculates the difference from the last month to the current month giving us the net activity. The difference is referenced on a separate worksheet that is formatted to our flat file requirements. What I would like to accomplish is that once a column has been completed – let’s say 5 days into the next month – that the column is locked and the data cannot be changed by the user. It would be an added bonus to have a password on the column so an administrator could change the figures, but in a controlled fashion.
Any assistance in resolving this would be appreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
daveed,
Is this a living document, or will it be used for one month only?

If living, I imagine you could hide set dates within the workbook for the first day of every month, and then construct some sort of test using the current day's date, subtracting the first of the current month and then looking at the difference. If greater than 4 then lock the relevant column.

e.g. In the workbook object in VBA:
Code:
Private Sub Workbook_Open()

'Set up variables representing the first days of the months in 2006.
DJan = 38718
DFeb = 38749
DMar = 38777
'etc.

Sheets("Sheet1").Unprotect Password:="PASSWORD"
'If current month is Jan, then use DJan and if 5th day of month or more
If Month(Date) = 1 And Date - DJan > 4 Then
    Sheets("Sheet1").Range("C:C").Locked = True
End If
'If current month is Feb, then use DFeb and if 5th day of month or more
If Month(Date) = 2 And Date - DFeb > 4 Then
    Sheets("Sheet1").Range("D:D").Locked = True
End If
'etc.

'Reprotect sheet
Sheets("Sheet1").Protect Password:="PASSWORD"

End Sub

You will need to change the sheet name and column references to suit your needs.

You cannot protect single columns with passwords - you will need to protect the entire sheet, having set the "Locked" cell property of each cell in the required columns to be True.

Try using the above code (adapted to your problem), and you should find you're on the way to getting the desired solution. Post back if you have any problems,

Matt
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,835
Members
449,051
Latest member
excelquestion515

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