VBA question

Good morning Techandmate,

Hope you are all doing good. Can anybody help in below problem. I am unable to do the same.

I have a "Sheet1"in a workbook. There are 2 ranges in this sheet, suppose "H:H" and "J:J".

I want to protect this 2 ranges in different passwords for different users.

Please solve this through vba coding.

Awaiting for your early response.

Thanks and have a great day.

Regards,

Debapriya






  Debapriya Bej

Hi,

Please check the below code, it should work for you-

Sub ProtectwithMultiRange()
Dim i As Integer
Dim j As Integer
Sheet1.Unprotect Password:="123"
i = Sheet1.Protection.AllowEditRanges.Count
For j = i To 1 Step -1
    Sheet1.Protection.AllowEditRanges(j).Delete
Next j
    Sheet1.Protection.AllowEditRanges.Add Title:="ColA", Range:=Columns( _
        "A:A"), Password:="abc"
    Sheet1.Protection.AllowEditRanges.Add Title:="ColB", Range:=Columns( _
        "B:B"), Password:="qwe"
    Sheet1.Protect Password:="123"
    
End Sub




  Devbrat Tripathi       17 Dec 2017       0       0     

Post Your Answers:

Please use the CODE HIGHLIGHT Button to format/highlight your codes if any