There are two different cases you might deal with, Show
Lock only few specific cells and rest of the cells in the work sheet are not locked Steps:
Note: If you wont provide the password then your cells will not be locked. Sub sumit() Dim mainworkBook As Workbook Set mainworkBook = ActiveWorkbook mainworkBook.Sheets("Main").Range("A1:C5").Value = "Locked" mainworkBook.Sheets("Main").Range("A1:C5").Locked = True ActiveSheet.Protect Password:="xx" End SubCell Lock Try editing any cell which is locked. Cell Lock 2Lock the Enitre worksheet except few cells
Code: Sub sumit() Dim mainworkBook As Workbook Set mainworkBook = ActiveWorkbook mainworkBook.Sheets("Main").Range("A1:C5").Value = "Free" mainworkBook.Sheets("Main").Range("A1:C5").Locked = False mainworkBook.Sheets("Main").Protect passowrd = "xx" End Subunlock specific cells -1 Change the cells which are free, and try changing rest of the cells unlock specific cells -2Related Posts:
This Excel VBA Protect Sheet Allow Select Locked Cells Tutorial is accompanied by an Excel workbook with the data and VBA code I use when describing the step-by-step process below. Get this example workbook (for free) by clicking the button below. The VBA code in the Excel workbook that accompanies this Excel VBA Protect Sheet Allow Select Locked Cells Tutorial is (always) stored in the Visual Basic Editor (VBE). If you don't know how to work with the VBE, I suggest you read my Visual Basic Editor (VBE) Tutorial. I link to this Tutorial in the Related Excel Macro and VBA Training Materials and Resources Section below. Table of Contents
Related Excel Macro and VBA Training Materials and ResourcesThe following Excel Macro and VBA Tutorials may help you better understand and implement the contents below.
This Excel VBA Protect Sheet Allow Select Locked Cells Tutorial is part of a more comprehensive series of Excel VBA Protect or Unprotect Sheet Tutorials.
You can find more Excel and VBA Tutorials in the organized Tutorials Archive: Click here to visit the Archives. If you want to learn how to automate Excel (and save time) by working with macros and VBA, you may be interested in the following Premium Excel Macro and VBA Training Materials:
If you want to save time when working with macros and VBA, you may be interested in AutoMacro: Click here to learn more about AutoMacro (affiliate link). AutoMacro is an add-in for VBA that installs directly into the VBE. Depending on the version, AutoMacro comes loaded with:
If you need consulting services, you may want to consider working with ExcelRescue. ExcelRescue is my usual suggestion for people who (like you) may need help with Excel tasks/projects: Click here to visit ExcelRescue (affiliate link). How do I select only unlocked cells in Excel?You can also press Ctrl+Shift+F or Ctrl+1. In the Format Cells popup, in the Protection tab, uncheck the Locked box and then click OK.
How do you unlock cells in Excel VBA?You aren't able to unlock the cells, even using VBA code, if the sheet is protected. So if you want to use code to unlock some cells, you have to unprotect the workbook/worksheet first.
How do I select individual cells in Excel VBA?Selecting a Single Cell Using VBA
Range(“A1”) tells VBA the address of the cell that we want to refer to. Select is a method of the Range object and selects the cells/range specified in the Range object. The cell references need to be enclosed in double quotes.
|