VBA code to Protect/Unprotect few columns in Excel

It is for Excel programming like Macro, function, formula, Pivot and other platform support..
alpeshviranik
Posts: 81
Joined: Thu Jul 17, 2014 4:58 pm
Contact:

VBA code to Protect/Unprotect few columns in Excel

Postby alpeshviranik » Sun Jul 27, 2014 10:02 pm

How to protect Excel sheet using VBA macro? Is there any way to protect only few row/column of worksheet using VBA? Is there any way to unprotect few Rows of worksheet using VBA?


Guest

Re: VBA code to Protect/Unprotect few columns in Excel

Postby Guest » Mon Jul 28, 2014 5:21 pm

Yes you can unprotect/protect only few rows/column using VBA code.
activesheet.unprotect will unprotect whole sheet. But below code will help you to unprotect selected rows. The idea is if you make row/column lock flag false then that row/column will remain unprotect.

Code: Select all

Worksheets("workshheetname").Range("A1:J40").Locked = False  'unprotect the A1 to J40 Row/column cell
        Worksheets("workshheetname").Range("H5:IG50").Locked = False
       
        Worksheets("workshheetname").Protect UserInterfaceOnly:=True, _
        DrawingObjects:=True, Contents:=True, _
        Scenarios:=True, AllowSorting:=True, AllowFiltering:=True, AllowFormattingRows:=True, AllowFormattingCells:=True, _
        AllowFormattingColumns:=True


Return to “Microsoft Excel and VBA Forum”

Who is online

Users browsing this forum: No registered users and 2 guests