Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 231
Default conditional formatting 1004 errors

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.FormatConditi ons.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -16776961
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default conditional formatting 1004 errors

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).SetFirs tPriority
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.FormatConditi ons.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -16776961
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 231
Default conditional formatting 1004 errors

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).SetFirs tPriority
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.FormatConditi ons.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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trapping errors with Conditional Formatting Sandusky Excel Discussion (Misc queries) 3 January 6th 09 08:52 PM
1004 Error in VBA Conditional Formatting Code €“ Fails in 2007 snicks Excel Programming 0 May 20th 08 05:42 PM
Conditional Formatting Errors CCW Excel Discussion (Misc queries) 2 September 15th 07 07:19 PM
Conditional Formatting - #N/A Errors JD2 Excel Discussion (Misc queries) 9 February 7th 07 10:01 AM
More 1004 Errors... Jim Berglund Excel Programming 1 May 8th 04 03:20 AM


All times are GMT +1. The time now is 11:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"