Run time error 1004, Unable to set the numberformat property of the range class

flds

Board Regular
Joined
Jun 19, 2008
Messages
73
Hi,
Need some help to figure out why I am getting this error message.
"run time error 1004,
unable to set the numberformat property of the range class"

I have recorded a macro to run a time duration of a game.
Cell A1 Start time 15:35
Cell A2 End time (click button to run the macro, see below)
Cell A3 Time difference fromula (=A2-A1) This cell is formated to [mm]

Everything works great, when the sheet is not protected.
When I protect the sheet, I get the error message.

[Note:
Without the Macro and the button and with the sheet protected, I use the Ctrl+Shift+: keys to record the End time. It works fine.]

Macro:
Sub GameDuration()

ActiveCell.FormulaR1C1 = Now()
Selection.NumberFormat = "h:mm"
ActiveCell.Offset(2, 0).Select
End Sub

Any help in solving the above would be very much appreciated.

Thanks
FLDS
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
The quick fix would be to use:
Code:
Sheets("Sheet1").Unprotect Password:="your_password"
.
. your code here
.
Sheets("Sheet1").Protect Password:="your_password"
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

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