ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code bombs at line indicated, why? (https://www.excelbanter.com/excel-programming/340152-code-bombs-line-indicated-why.html)

Jim May

Code bombs at line indicated, why?
 
Sub TestForProtect()
Dim myrng As Range
Dim c As Range
Set myrng = Range("A1:B5")
For Each c In myrng
If c.Locked = False Then
c.Interior.ColorIndex = 6 <<< R/T 1004 ***
End If
Next c
End Sub

*** Unable to set the Colorindex property of the Iterior Class... ????

How can I fix?
TIA,



Wolf

Code bombs at line indicated, why?
 
One possibility is, that you have your sheet protected.
If so, unprotect it in the beginning and protect it at the end of the macro.

Wolf

"Jim May" wrote:

Sub TestForProtect()
Dim myrng As Range
Dim c As Range
Set myrng = Range("A1:B5")
For Each c In myrng
If c.Locked = False Then
c.Interior.ColorIndex = 6 <<< R/T 1004 ***
End If
Next c
End Sub

*** Unable to set the Colorindex property of the Iterior Class... ????

How can I fix?
TIA,




Tom Ogilvy

Code bombs at line indicated, why?
 
If the sheet is protected, then even an unlocked cell can not normally be
formatted. (in xl2002 and later, there are options for this). In general,
things that you can't do manually can not be done in code either. You also
might look at the UserInterFaceOnly setting of the protect method for
greater flexibility.

--
Regards,
Tom Ogilvy

"Jim May" wrote in message
news:pldWe.23744$8q.15872@lakeread01...
Sub TestForProtect()
Dim myrng As Range
Dim c As Range
Set myrng = Range("A1:B5")
For Each c In myrng
If c.Locked = False Then
c.Interior.ColorIndex = 6 <<< R/T 1004 ***
End If
Next c
End Sub

*** Unable to set the Colorindex property of the Iterior Class... ????

How can I fix?
TIA,





Jim May

Code bombs at line indicated, why?
 
Thanks Tom,

"Tom Ogilvy" wrote in message
...
If the sheet is protected, then even an unlocked cell can not normally be
formatted. (in xl2002 and later, there are options for this). In
general,
things that you can't do manually can not be done in code either. You
also
might look at the UserInterFaceOnly setting of the protect method for
greater flexibility.

--
Regards,
Tom Ogilvy

"Jim May" wrote in message
news:pldWe.23744$8q.15872@lakeread01...
Sub TestForProtect()
Dim myrng As Range
Dim c As Range
Set myrng = Range("A1:B5")
For Each c In myrng
If c.Locked = False Then
c.Interior.ColorIndex = 6 <<< R/T 1004 ***
End If
Next c
End Sub

*** Unable to set the Colorindex property of the Iterior Class... ????

How can I fix?
TIA,








All times are GMT +1. The time now is 10:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com