PC Review


Reply
Thread Tools Rate Thread

conditional formatting 1004 errors

 
 
Sarah
Guest
Posts: n/a
 
      25th Sep 2008
I'm a rookie. I am getting Run-time error '1004': Unable to set the Bold
property of the Font class with the following code:

Range("I10:I1000").Select

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -16776961
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True

Thank you
 
Reply With Quote
 
 
 
 
RyanH
Guest
Posts: n/a
 
      25th Sep 2008
Is the sheet you are trying to apply the formats protected? If so, you need
to unprotect the worksheet first then reapply the protection.

Sub TEST()

' unprotect sheet first
Sheets("Sheet1").Unprotect Password:="password"

' your code
With Range("I10:I1000")
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"

.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -16776961
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = True
End With

' protect sheet
Sheets("Sheet1").Protect Password:="password"

End Sub

Hope this helps! If so, let me know by clicking YES below.
--
Cheers,
Ryan


"Sarah" wrote:

> I'm a rookie. I am getting Run-time error '1004': Unable to set the Bold
> property of the Font class with the following code:
>
> Range("I10:I1000").Select
>
> Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
> "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
>
> Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
> With Selection.FormatConditions(1).Font
> .Bold = True
> .Italic = False
> .Color = -16776961
> .TintAndShade = 0
> End With
> Selection.FormatConditions(1).StopIfTrue = True
>
> Thank you

 
Reply With Quote
 
Sarah
Guest
Posts: n/a
 
      26th Sep 2008
No, it's not protected.

"RyanH" wrote:

> Is the sheet you are trying to apply the formats protected? If so, you need
> to unprotect the worksheet first then reapply the protection.
>
> Sub TEST()
>
> ' unprotect sheet first
> Sheets("Sheet1").Unprotect Password:="password"
>
> ' your code
> With Range("I10:I1000")
> .FormatConditions.Add Type:=xlExpression, Formula1:= _
> "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
>
> .FormatConditions(.FormatConditions.Count).SetFirstPriority
> With .FormatConditions(1).Font
> .Bold = True
> .Italic = False
> .Color = -16776961
> .TintAndShade = 0
> End With
> .FormatConditions(1).StopIfTrue = True
> End With
>
> ' protect sheet
> Sheets("Sheet1").Protect Password:="password"
>
> End Sub
>
> Hope this helps! If so, let me know by clicking YES below.
> --
> Cheers,
> Ryan
>
>
> "Sarah" wrote:
>
> > I'm a rookie. I am getting Run-time error '1004': Unable to set the Bold
> > property of the Font class with the following code:
> >
> > Range("I10:I1000").Select
> >
> > Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
> > "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
> >
> > Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
> > With Selection.FormatConditions(1).Font
> > .Bold = True
> > .Italic = False
> > .Color = -16776961
> > .TintAndShade = 0
> > End With
> > Selection.FormatConditions(1).StopIfTrue = True
> >
> > Thank you

 
Reply With Quote
 
Sarah
Guest
Posts: n/a
 
      26th Sep 2008
Interestingly, I have found if I change the conditional formatting to shade
the cells, the macro works. With the code exactly the same, except as follows:

With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0

Bug?

"RyanH" wrote:

> Is the sheet you are trying to apply the formats protected? If so, you need
> to unprotect the worksheet first then reapply the protection.
>
> Sub TEST()
>
> ' unprotect sheet first
> Sheets("Sheet1").Unprotect Password:="password"
>
> ' your code
> With Range("I10:I1000")
> .FormatConditions.Add Type:=xlExpression, Formula1:= _
> "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
>
> .FormatConditions(.FormatConditions.Count).SetFirstPriority
> With .FormatConditions(1).Font
> .Bold = True
> .Italic = False
> .Color = -16776961
> .TintAndShade = 0
> End With
> .FormatConditions(1).StopIfTrue = True
> End With
>
> ' protect sheet
> Sheets("Sheet1").Protect Password:="password"
>
> End Sub
>
> Hope this helps! If so, let me know by clicking YES below.
> --
> Cheers,
> Ryan
>
>
> "Sarah" wrote:
>
> > I'm a rookie. I am getting Run-time error '1004': Unable to set the Bold
> > property of the Font class with the following code:
> >
> > Range("I10:I1000").Select
> >
> > Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
> > "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
> >
> > Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
> > With Selection.FormatConditions(1).Font
> > .Bold = True
> > .Italic = False
> > .Color = -16776961
> > .TintAndShade = 0
> > End With
> > Selection.FormatConditions(1).StopIfTrue = True
> >
> > Thank you

 
Reply With Quote
 
RyanH
Guest
Posts: n/a
 
      26th Sep 2008
Do you already have a format condition in that range? If so, I think you
will have to delete the old condition and apply the new one. For example:

Range("A1:A10").FormatConditions.Delete
Range("A1:A30").FormatConditions.Add Type:=xlExpression, Formula1:= _
"=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"

Hope this helps! If so, let me know by clicking "YES" below.
--
Cheers,
Ryan


"Sarah" wrote:

> No, it's not protected.
>
> "RyanH" wrote:
>
> > Is the sheet you are trying to apply the formats protected? If so, you need
> > to unprotect the worksheet first then reapply the protection.
> >
> > Sub TEST()
> >
> > ' unprotect sheet first
> > Sheets("Sheet1").Unprotect Password:="password"
> >
> > ' your code
> > With Range("I10:I1000")
> > .FormatConditions.Add Type:=xlExpression, Formula1:= _
> > "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
> >
> > .FormatConditions(.FormatConditions.Count).SetFirstPriority
> > With .FormatConditions(1).Font
> > .Bold = True
> > .Italic = False
> > .Color = -16776961
> > .TintAndShade = 0
> > End With
> > .FormatConditions(1).StopIfTrue = True
> > End With
> >
> > ' protect sheet
> > Sheets("Sheet1").Protect Password:="password"
> >
> > End Sub
> >
> > Hope this helps! If so, let me know by clicking YES below.
> > --
> > Cheers,
> > Ryan
> >
> >
> > "Sarah" wrote:
> >
> > > I'm a rookie. I am getting Run-time error '1004': Unable to set the Bold
> > > property of the Font class with the following code:
> > >
> > > Range("I10:I1000").Select
> > >
> > > Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
> > > "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
> > >
> > > Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
> > > With Selection.FormatConditions(1).Font
> > > .Bold = True
> > > .Italic = False
> > > .Color = -16776961
> > > .TintAndShade = 0
> > > End With
> > > Selection.FormatConditions(1).StopIfTrue = True
> > >
> > > Thank you

 
Reply With Quote
 
Sarah
Guest
Posts: n/a
 
      26th Sep 2008
You're right! That worked. My other reply had worked only because I had
deleted the existing conditional formatting. Thanks!

"RyanH" wrote:

> Do you already have a format condition in that range? If so, I think you
> will have to delete the old condition and apply the new one. For example:
>
> Range("A1:A10").FormatConditions.Delete
> Range("A1:A30").FormatConditions.Add Type:=xlExpression, Formula1:= _
> "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
>
> Hope this helps! If so, let me know by clicking "YES" below.
> --
> Cheers,
> Ryan
>
>
> "Sarah" wrote:
>
> > No, it's not protected.
> >
> > "RyanH" wrote:
> >
> > > Is the sheet you are trying to apply the formats protected? If so, you need
> > > to unprotect the worksheet first then reapply the protection.
> > >
> > > Sub TEST()
> > >
> > > ' unprotect sheet first
> > > Sheets("Sheet1").Unprotect Password:="password"
> > >
> > > ' your code
> > > With Range("I10:I1000")
> > > .FormatConditions.Add Type:=xlExpression, Formula1:= _
> > > "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
> > >
> > > .FormatConditions(.FormatConditions.Count).SetFirstPriority
> > > With .FormatConditions(1).Font
> > > .Bold = True
> > > .Italic = False
> > > .Color = -16776961
> > > .TintAndShade = 0
> > > End With
> > > .FormatConditions(1).StopIfTrue = True
> > > End With
> > >
> > > ' protect sheet
> > > Sheets("Sheet1").Protect Password:="password"
> > >
> > > End Sub
> > >
> > > Hope this helps! If so, let me know by clicking YES below.
> > > --
> > > Cheers,
> > > Ryan
> > >
> > >
> > > "Sarah" wrote:
> > >
> > > > I'm a rookie. I am getting Run-time error '1004': Unable to set the Bold
> > > > property of the Font class with the following code:
> > > >
> > > > Range("I10:I1000").Select
> > > >
> > > > Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
> > > > "=(AND(ABS($J10)>$G$5,ABS($I10)>$G$4))"
> > > >
> > > > Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
> > > > With Selection.FormatConditions(1).Font
> > > > .Bold = True
> > > > .Italic = False
> > > > .Color = -16776961
> > > > .TintAndShade = 0
> > > > End With
> > > > Selection.FormatConditions(1).StopIfTrue = True
> > > >
> > > > Thank you

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1004 Error in VBA Conditional Formatting Code – Fails in 2007 snicks Microsoft Excel Programming 0 20th May 2008 05:42 PM
Conditional Formatting Errors =?Utf-8?B?Q0NX?= Microsoft Excel Misc 2 15th Sep 2007 07:19 PM
RE: Conditional Formatting - #N/A Errors =?Utf-8?B?TGVv?= Microsoft Excel Misc 2 7th Feb 2007 10:01 AM
Re: Conditional Formatting - #N/A Errors Peo Sjoblom Microsoft Excel Misc 1 11th Jan 2007 04:35 AM
Conditional Formatting Errors =?Utf-8?B?S2VycnkgUHVyZHk=?= Microsoft Access 1 23rd Jun 2006 02:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:32 AM.