Run-Time error 1004 Help

savio

Board Regular
Joined
Sep 3, 2005
Messages
144
I used the following vba code to add the date. it is seem to works probably , BUT if i protect the sheet I got the following error :

Run-Time error 1004

Unable to set the NumberFormat property of the Range class.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim i As Integer
For i = 4 To 100
If Cells(i, "B").Value <> "" And Cells(i, "G").Value = "" Then

Cells(i, "G").Value = Date & " " & Time
Cells(i, "G").NumberFormat = "M/D/yyyy h:mm AM/PM"

End If


If Cells(i, "K").Value <> "" And Cells(i, "N").Value = "" Then

Cells(i, "N").Value = Date & " " & Time
Cells(i, "N").NumberFormat = "M/D/yyyy h:mm AM/PM"

End If

If Cells(i, "V").Value <> "" And Cells(i, "X").Value = "" Then

Cells(i, "X").Value = Date & " " & Time
Cells(i, "X").NumberFormat = "M/D/yyyy h:mm AM/PM"

End If


Next

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
A lot of macros won't work with protected sheets. I don't know why in your case exactly, but this happened to me when I was trying to use a macro that involved a formula, I couldn't input any data if I protected the sheet.

For example I had a button to run a formula that would add numbers in a column together, but if I protected the sheet, I got the same error as you did. Then I couldn't input any new data in the column. Why do you need to protect the sheet?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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