automating locking of group of cells

%3CLINGO-SUB%20id%3D%22lingo-sub-2362687%22%20slang%3D%22en-US%22%3Eautomating%20locking%20of%20group%20of%20cells%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2362687%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Excel%20Nerds.%20I%20need%20to%20know%20if%20excel%20has%20this%20capacity.%20We%20have%20an%20excel%20workbook%20that%20has%20multiple%20sheets%20labeled%20as%20months%20and%20repeating%20tables%20on%20each%20sheet%20representing%20each%20day.%20Is%20there%20anyway%20that%20once%20a%20day%20is%20over%2C%20say%20midnight%20every%20night%2C%20that%20the%20table%20associated%20with%20that%20day%20gets%20locked%20automatically%20without%20someone%20manually%20having%20to%20lock%20it%3F%20I%20am%20looking%20to%20protect%20the%20sheet%2C%20but%20only%20for%20the%20parts%20that%20have%20passed%20in%20time%20since%20each%20table%20represents%20data%20from%20each%20day.%20historical%20data%20needs%20to%20be%20protected%2C%20which%20the%20currenty%20real-time%20day%20data%20can%20be%20entered%20by%20multiple%20people.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2362687%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2363079%22%20slang%3D%22en-US%22%3ERe%3A%20automating%20locking%20of%20group%20of%20cells%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2363079%22%20slang%3D%22en-US%22%3EThis%20needs%20VBA%20macro%2C%2C%2C%20if%20you%20are%20comfortable%20then%20edit%20your%20post%20and%20add%20new%20line%20as%20well%20the%20Tag%20VBA%20to%20the%20post%20!!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2366390%22%20slang%3D%22en-US%22%3ERe%3A%20automating%20locking%20of%20group%20of%20cells%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2366390%22%20slang%3D%22en-US%22%3EHey%20Rajesh-S!%20Thanks%20for%20the%20response.%20I%20watched%20some%20videos%20on%20VBA%20Macro.%20I%20don't%20think%20I'm%20equipped%20to%20figure%20it%20out%20and%20make%20it%20do%20what%20I%20need.%20Can%20you%20advise%20about%20where%20I%20can%20get%20outside%20help%20on%20this%3F%20Much%20appreciated!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2367544%22%20slang%3D%22en-US%22%3ERe%3A%20automating%20locking%20of%20group%20of%20cells%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2367544%22%20slang%3D%22en-US%22%3EIf%20possible%20attach%20the%20WB%20having%20the%20sheet%20has%20Group%20of%20Cells%20then%20I'll%20show%20you%20how%20to%20work%20with%20VBA%20macro%20!!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382151%22%20slang%3D%22en-US%22%3ERe%3A%20automating%20locking%20of%20group%20of%20cells%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382151%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F93699%22%20target%3D%22_blank%22%3E%40Rajesh-S%3C%2FA%3E%26nbsp%3B%20Hey!%26nbsp%3B%20Thanks%20for%20the%20offer%2C%20I%20appreciate%20the%20help%20very%20much.%20I've%20attached%20a%20blank%20version%20of%20the%20workbook%20that%20need%20help%20with.%20Maybe%20you%20could%20use%20it%20to%20instruct%20me.%20Go%20to%20the%20Oct%202021%20tab%20and%20see%20the%20tables%20at%20the%20very%20top%20that%20are%20labled.%20Each%20repeating%20row%20of%20tables%20represent%20a%20day%20in%20the%20month%20of%20October.%20Everyday%20data%20gets%20put%20into%20the%20empty%20cells%20by%20multiple%20people.%26nbsp%3B%20At%20the%20end%20of%20the%20day%20at%2011pm%2C%20I%20would%20like%20those%20tables%20to%20become%20locked%20for%20security%20reasons%20and%20continue%20to%20automatically%20lock%20as%20each%20day%20passes%20at%2011pm.%26nbsp%3B%20%26nbsp%3BI've%20attached%20the%20workbook%20and%20a%20pdf%20showing%20exactly%20which%20group%20of%20cells%20(circled%20in%20red)%20that%20needs%20to%20be%20locked%20with%20each%20passing%20day.%20Let%20me%20know%20if%20there%20is%20a%20way%20to%20make%20this%20happen%20in%20VBA%20Macros.%20I%20am%20eager%20to%20have%20more%20knowledge%20under%20my%20belt%2C%20so%20again%2C%20much%20appreciated!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382576%22%20slang%3D%22en-US%22%3ERe%3A%20automating%20locking%20of%20group%20of%20cells%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382576%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1056295%22%20target%3D%22_blank%22%3E%40maker340%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20will%20help%20you%2C%20protects%20particular%20Sheet%20at%20particular%20TIME.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EPrivate%20Sub%20Workbook_Open()%0AApplication.OnTime%20Now%20%2B%20TimeValue(%2211%3A00%3A00%22)%2C%20%22ProtectMysheets%22%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EWhere%20ProtectMysheets%20is%20also%20VBA%20macro.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20code%20has%20Sheet%20name%20along%20with%20Passcode.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20ProtectMysheets()%0A%20%20%20Sheets(%22Sheet1%22).Protect%20Password%3A%3D%22YourPassword%22%0A%20%20%20Sheets(%22Sheet5%22).Protect%20Password%3A%3D%22YourPassword%22%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EYou%20may%20add%20as%20many%20Sheets%20%26amp%3B%20replace%20YourPassword%20with%20a%20Pass%20code%20of%20your%20choice%2C%20remember%20Pass%20code%20is%20Case%20sensitive.%26nbsp%3B%3C%2FLI%3E%3CLI%3ESuggested%20to%20protect%20entire%20sheet%20instead%20of%20TABLE%20since%20sheet%20has%20many%20Tables.%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EBut%20if%20you%20are%20disparately%20looking%20to%20lock%20the%20Table%20then%20use%20the%20following%20VBA%20code%2C%20lock%20Range%20of%20cells%2C%20you%20need%20to%20use%20the%20cell%20range%20to%20lock%20particular%20Table.%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPrivate%20Sub%20workbook_open()%0A%0ADim%20systime%20As%20String%0ADim%20mypassword%20As%20String%0A%0Asystime%20%3D%20Format(Now%2C%20%22hh%3Amm%3Ass%22)%0Amypassword%20%3D%20%22abcd%22%0A%0AIf%20TimeValue(systime)%20%26gt%3B%20TimeValue(%2211%3A00%3A00%22)%20Then%0A%0AWith%20ThisWorkbook.ActiveSheet%0A%0A%20%20%20%20.Unprotect%20Password%3A%3Dmypassword%0A%20%20%20%20.Range(%22B2%3AF40%22).Locked%20%3D%20True%0A%20%20%20%20.Protect%20Password%3A%3Dmypassword%0A%0AEnd%20With%0A%0AThisWorkbook.Save%0A%0AEnd%20If%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EWhere%20Pass%20code%20abcd%2C%20Time%2011%3A00%3A00%20%26amp%3B%20Range%20for%20Table%20B2%3AF40%20are%20editable.%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hey Excel Nerds. I need to know if excel has this capacity. We have an excel workbook that has multiple sheets labeled as months and repeating tables on each sheet representing each day. Is there anyway that once a day is over, say midnight every night, that the table associated with that day gets locked automatically without someone manually having to lock it? I am looking to protect the sheet, but only for the parts that have passed in time since each table represents data from each day. historical data needs to be protected, which the currenty real-time day data can be entered by multiple people. 

9 Replies
This needs VBA macro,,, if you are comfortable then edit your post and add new line as well the Tag VBA to the post !!
Hey Rajesh-S! Thanks for the response. I watched some videos on VBA Macro. I don't think I'm equipped to figure it out and make it do what I need. Can you advise about where I can get outside help on this? Much appreciated!
If possible attach the WB having the sheet has Group of Cells then I'll show you how to work with VBA macro !!

@Rajesh-S  Hey!  Thanks for the offer, I appreciate the help very much. I've attached a blank version of the workbook that need help with. Maybe you could use it to instruct me. Go to the Oct 2021 tab and see the tables at the very top that are labled. Each repeating row of tables represent a day in the month of October. Everyday data gets put into the empty cells by multiple people.  At the end of the day at 11pm, I would like those tables to become locked for security reasons and continue to automatically lock as each day passes at 11pm.   I've attached the workbook and a pdf showing exactly which group of cells (circled in red) that needs to be locked with each passing day. Let me know if there is a way to make this happen in VBA Macros. I am eager to have more knowledge under my belt, so again, much appreciated!

@maker340 

 

This will help you, protects particular Sheet at particular TIME.

 

Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("11:00:00"), "ProtectMysheets"
End Sub

Where ProtectMysheets is also VBA macro.

 

This code has Sheet name along with Passcode.

Sub ProtectMysheets()
   Sheets("Sheet1").Protect Password:="YourPassword"
   Sheets("Sheet5").Protect Password:="YourPassword"
End Sub

 

  • You may add as many Sheets & replace YourPassword with a Pass code of your choice, remember Pass code is Case sensitive. 
  • Suggested to protect entire sheet instead of TABLE since sheet has many Tables.

 

But if you are disparately looking to lock the Table then use the following VBA code, lock Range of cells, you need to use the cell range to lock particular Table. 

 

Private Sub workbook_open()

Dim systime As String
Dim mypassword As String

systime = Format(Now, "hh:mm:ss")
mypassword = "abcd"

If TimeValue(systime) > TimeValue("11:00:00") Then

With ThisWorkbook.ActiveSheet

    .Unprotect Password:=mypassword
    .Range("B2:F40").Locked = True
    .Protect Password:=mypassword

End With

ThisWorkbook.Save

End If

End Sub

 

  • Where Pass code abcd, Time 11:00:00 & Range for Table B2:F40 are editable.

 

@Rajesh-S 

Hey! Thanks for the codes. I am going to attempt to make this happen with the last one you provided. I've been trying to put the code into a module, but nothing is happening and I can't seem to be able to run the macro. Am I doing something wrong? Should I be inputting this elsewhere? I'm selecting the sheet labeled MAY 2021 in the excel file, right-clicking and selecting View Code, which bring up the VBA window. see image.

maker340_0-1622076531031.png

Then I select Sheet 6(MAY 2021) from the project box and right click on INSERT to select MODULE. Once the module box pops up, I copy the code you provided with adjustments to the password and time as needed.   After that, I don't know how to test it or run it to make it work. 

maker340_2-1622076776492.png

Can you help me out?  I have never worked with VBA Macro before

Thank you!

 

 

 

Noo,,, as soon you reach to the VBA editor,,, simply Copy & Paste any of the codes is required,,, and Excel will save it as STANDARD MODULE,, no need to Save as MODULE !! Do this select the Sheet where you want to apply the MACRO,, either press ALT+F11 or Right Click the Sheet Tab,,, and hit View Code,,, you find VB editor is now open,, the Copy & Paste any code,,, remember first two Macros are related to each other,, so Copy them together,,, 3 rd one is independent,, also Either use 1st & 2nd or ONLY 3rd,,, otherwise you get an Error since it will duplicate the WORKBOOK OPEN event,,, SAVE & Return to Sheet.. Close the Workbook. Now as soon you open the same Workbook,,, find the effects !!

@Rajesh-S 

Rajesh-S, do I have to use military time format? I've tried using both options, 1&2 together as well as the 3rd code by itself and nothing is happening. If the locking works, then I shouldn't be able to delete any data in either the sheets I've chosen to lock or in the cells I've input in the RANGE, right? What am I missing?

@maker340 

 

Check the attached Workbook has one sheet & Two tables, Table one has range A1:B10 is protected.

 

How it works:

  1. As soon you open this WB, Excel will prompt you to write Pass code, which abcd is small letters.
  2. Write PW & hit Ok.
  3. Now you find Table 1 , (Range A1:B10) is protected, you can't move MOUSE over the Range/Table.
  4. If you wanna to Unprotected the Table then hit REVIEW Tab then Unprotect Sheet command & write the PW (abcd). 
  5. You may change the PW is in VBA code.
  6. To view the code hit either ALT+F11 or Right Click Sheet Tab ,, the View Code.
  7. Now check the Left Top of the Screen, you find the Project Explorer,, find & hit ThisWorkbook Icon.
  8. You may add more Range for other Tables and accordingly need to modify the VBA code.

N.B.

 

If you are using military Time then no need to modify the code, accordingly  convert Military time to Standard since EXCEL by default considers Standard Time,,,, few are like 1300 hrs of 1 A M. 2400 for 12 mid night, 1930 for 07:30 PM, 031503 is 03:15:03 AM.