SOLVED

1004 error application-defined or object-defined error......Cannot figure out why

Copper Contributor

I have code that clears changes the color index of a cell.  When I execute the code on a Workbook that I just opened and select the sheet I get the 1004 error on the first range statement below. Does anyone have an idea why I am getting this?

 

 

 

Worksheets("Measurement Form").Activate
'
'
'Resets "Values Changed" Indicator to White Font or Black Font
Range("J4").Font.ColorIndex = 2
Range("B7").Font.ColorIndex = 1

4 Replies

@jragan 

Has the Measurement Form worksheet been protected?

best response confirmed by allyreckerman (Microsoft)
Solution

@jragan 

By default, cells on a protected sheet cannot be formatted.

 

One solution is tick the check box 'Format Cells' in the 'Protect Sheet' dialog when you protect the sheet.

 

Another is to temporarily unprotect the sheet:

    ...
    ActiveSheet.Unprotect Password:="secret"
    Range("J4").Font.ColorIndex = 2
    Range("B7").Font.ColorIndex = 1
    ActiveSheet.Protect Password:="secret"
1 best response

Accepted Solutions
best response confirmed by allyreckerman (Microsoft)
Solution

@jragan 

By default, cells on a protected sheet cannot be formatted.

 

One solution is tick the check box 'Format Cells' in the 'Protect Sheet' dialog when you protect the sheet.

 

Another is to temporarily unprotect the sheet:

    ...
    ActiveSheet.Unprotect Password:="secret"
    Range("J4").Font.ColorIndex = 2
    Range("B7").Font.ColorIndex = 1
    ActiveSheet.Protect Password:="secret"

View solution in original post