Hi Daniel,

I think you're getting the error when the sheet is protected when you access the line:
 Range("D1:D1000000").NumberFormat = "0"
There does not seem to be an error when the sheet is NOT protected when you access the line.

I can't suggest a fix, because I'm not sure what you're trying to do.

Lewis