Always keep Enable "Format Cells"

RLPeloquin

Board Regular
Joined
Jul 4, 2020
Messages
73
Office Version
  1. 2019
Platform
  1. Windows
I have a command button that is used to clear my worksheet. Is there a way to always keep the Enable Format Cells checked thru C7:N7 with VBA code? Thanks, in advance
Would the problem be in this code and where and how would I write it, if possible.

Private Sub CommandButton1_Click()
Dim answer As Integer
Dim x As Integer
If CommandButton1 = False Then
answer = MsgBox("Do You Want To Clear Sheet and Start Anew", vbYesNoCancel)

If answer = vbYes Then
x = MsgBox("Do you need to Print before deleting data?", vbYesNo)
If x = vbYes Then
ActiveWindow.SelectedSheets.PrintOut copies:=1, collate:=True
ActiveSheet.Unprotect

Range("A7").Value = "" 'If Cell is a Protected Cell put ActiveSheet.Unprotect above code
Range("C10").Value = "=If(N10 = """","""",N9)"
Range("D10").Value = "=If(D9 = """","""",C9)"
Range("E10").Value = "=If(E9 = """","""",D9)"
Range("F10").Value = "=If(F9 = """","""",E9)"
Range("G10").Value = "=If(G9 = """","""",F9)"
Range("H10").Value = "=If(H9 = """","""",G9)"
Range("I10").Value = "=If(I9 = """","""",H9)"
Range("J10").Value = "=If(J9 = """","""",I9)"
Range("K10").Value = "=If(K9 = """","""",J9)"
Range("L10").Value = "=If(L9 = """","""",K9)"
Range("M10").Value = "=If(M9 = """","""",L9)"
Range("N10").Value = "=If(N9 = """","""",M9)"
ActiveSheet.Protect


Range("B2").Value = ""
Range("C3").Value = ""
Range("B4").Value = ""
Range("E4").Value = ""
Range("G4").Value = ""
Range("B5").Value = ""
Range("B6").Value = ""
Range("C7:N7").Value = ""
Range("C9:N9").Value = ""
Range("C17:N17").Value = ""
Range("C20").Value = ""
Range("F20").Value = ""
Range("A22:A33").Value = ""
ActiveSheet.Protect
ElseIf x = vbNo Then

ActiveSheet.Unprotect
Range("C10").Value = "=If(N10 = """","""",N9)"
Range("D10").Value = "=If(D9 = """","""",C9)"
Range("E10").Value = "=If(E9 = """","""",D9)"
Range("F10").Value = "=If(F9 = """","""",E9)"
Range("G10").Value = "=If(G9 = """","""",F9)"
Range("H10").Value = "=If(H9 = """","""",G9)"
Range("I10").Value = "=If(I9 = """","""",H9)"
Range("J10").Value = "=If(J9 = """","""",I9)"
Range("K10").Value = "=If(K9 = """","""",J9)"
Range("L10").Value = "=If(L9 = """","""",K9)"
Range("M10").Value = "=If(M9 = """","""",L9)"
Range("N10").Value = "=If(N9 = """","""",M9)"
ActiveSheet.Protect

Range("B2").Value = ""
Range("C3").Value = ""
Range("B4").Value = ""
Range("E4").Value = ""
Range("G4").Value = ""
Range("B5").Value = ""
Range("B6").Value = ""
Range("C7:N7").Value = ""
Range("C9:N9").Value = ""
Range("C17:N17").Value = ""
Range("C20").Value = ""
Range("F20").Value = ""
Range("A22:A33").Value = ""
ActiveSheet.Unprotect
Range("A7").Value = ""
ActiveSheet.Protect
ElseIf answer = vbNo Then
Exit Sub
Else
Exit Sub
End If
End If
End If
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe another workaround. Is it possible to write a IF statement such as: If cell C7 is the selected cell then "Enable Format Cells." Thanks for any help. My problem is having a pop up calendar that will not keep the "Enable Format Cells" checked with the way I have written my code. Can not figure it out. Thanks
 
Upvote 0
This seems to work. Thanks anyway everybody
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Protect , AllowFormattingCells:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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