mdavis0510
mdavis0510

Reputation: 59

Run-time error '1004' Unable to set the NumberFormat property of Range Class

I installed a very simple command button to timestamp a selected cell. The command button works completely fine until I protect the sheet, then it throws the error mentioned in the title. I have already checked that the cells' format is not selected to 'locked'.

Private Sub CommandButton1_Click()
Dim ts As Date

With Selection

.Value = Now

.NumberFormat = "h:mm AM/PM"

End With
End Sub

Upvotes: 2

Views: 12098

Answers (1)

VBasic2008
VBasic2008

Reputation: 54883

AllowFormattingCells

You have to allow Formatting of cells.

enter image description here

or in VBA

ActiveSheet.Protect AllowFormattingCells:=True

Upvotes: 4

Related Questions