Unlocking Columns after VBA Code

azdisplcdgrl

New Member
Joined
Aug 2, 2016
Messages
1
Hello. I am a noob to excel vba. I found this great code that gives me part of what I need. However, I do not want columns C & F locked after entry. I've tried a few things, but it's not working. Can anyone help?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 4 Then
confirm = MsgBox("Do you want to sign up for this OT?" & vbCrLf & "By selecting Yes, you agree to accept OT, once selected, this cannot be changed.", vbYesNo, "confirm Entry")
Select Case confirm
Case Is = vbYes
Dim Cell As Range
With ActiveSheet
    .Unprotect Password:="Kaia"
    .Cells.Locked = False
    For Each Cell In ActiveSheet.UsedRange
        If Cell.Value = "" Then
            Cell.Locked = False
     Cell.Locked = True
     End If
   Next Cell
   .Protect Password:="Kaia"
   End With
  Case Is = vbNo
  Application.Undo
  End Select
 End If
 Application.EnableEvents = True
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try adding the 2 lines of code below:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 4 Then
confirm = MsgBox("Do you want to sign up for this OT?" & vbCrLf & "By selecting Yes, you agree to accept OT, once selected, this cannot be changed.", vbYesNo, "confirm Entry")
Select Case confirm
Case Is = vbYes
Dim Cell As Range
With ActiveSheet
    .Unprotect Password:="Kaia"
    .Cells.Locked = False
    For Each Cell In ActiveSheet.UsedRange
        If Cell.Value = "" Then
            Cell.Locked = False
     Cell.Locked = True
     End If
   Next Cell


    .Columns("C:C").Locked = False
    .Columns("F:F").Locked = False




   .Protect Password:="Kaia"
   End With
  Case Is = vbNo
  Application.Undo
  End Select
 End If
 Application.EnableEvents = True
End Sub

Mark
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,087
Members
452,542
Latest member
Bricklin

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