Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete Individual FormatCondition gives 1004 Error

Hi

I am trying to search through FormatConditions in my Worksheet that
intersect with a target range and delete them. When I attempt to delete a
single FormatCondition I get a 1004 error.

In addition I am looking for equivalent functionality to Excel 2007's
FormatCondition's AppliesTo Property in Excel 2003 if any one has any
pointers.

A sample macro that demonstrates the deletion problem is below: -

Dim s As Worksheet
Set s = Sheets("Sheet1")

Dim fc As FormatCondition

' clear the entire sheet first
s.Cells.FormatConditions.Delete

' set up 3 overlapping ranges
' 1:5, 3:7, 5:9 = i*2-1:i*2+3
Dim ranges(1 To 3) As Range
Dim i As Integer
For i = 1 To 3
Set ranges(i) = s.Range(s.Cells(i * 2 - 1, i * 2 - 1), s.Cells(i * 2
+ 3, i * 2 + 3))
Set fc = ranges(i).FormatConditions.Add(xlExpression, xlEqual,
"=MOD(ROW()+16,2)0")
fc.Interior.Color = RGB(0, 0, 70 + 60 * i)
Next i

' want to delete any FormatCondition intersecting
' with targetRange. loop through all FCs on sheet
' and delete if intersects.
Set targetRange = Sheets("Sheet1").Range("F3:F3")

For Each fc In s.Cells.FormatConditions
'MsgBox fc.AppliesTo.Address
If Not Intersect(fc.AppliesTo, targetRange) Is Nothing Then
' want to delete this FC but AppliesTo only works in XL2007
fc.AppliesTo.Select
End If
Next fc

' actually just trying to delete an individual
' formatcondition gives an 1004 error
s.Cells.FormatConditions(2).Delete

Has any one had any similar problems?
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Delete Individual FormatCondition gives 1004 Error

Make sure there is a format condition before you do the delete. try code
like this

For i = 1 To Range("B6").FormatConditions.Count
Range("B6").FormatConditions(i).Delete
Next i

"bsdz" wrote:

Hi

I am trying to search through FormatConditions in my Worksheet that
intersect with a target range and delete them. When I attempt to delete a
single FormatCondition I get a 1004 error.

In addition I am looking for equivalent functionality to Excel 2007's
FormatCondition's AppliesTo Property in Excel 2003 if any one has any
pointers.

A sample macro that demonstrates the deletion problem is below: -

Dim s As Worksheet
Set s = Sheets("Sheet1")

Dim fc As FormatCondition

' clear the entire sheet first
s.Cells.FormatConditions.Delete

' set up 3 overlapping ranges
' 1:5, 3:7, 5:9 = i*2-1:i*2+3
Dim ranges(1 To 3) As Range
Dim i As Integer
For i = 1 To 3
Set ranges(i) = s.Range(s.Cells(i * 2 - 1, i * 2 - 1), s.Cells(i * 2
+ 3, i * 2 + 3))
Set fc = ranges(i).FormatConditions.Add(xlExpression, xlEqual,
"=MOD(ROW()+16,2)0")
fc.Interior.Color = RGB(0, 0, 70 + 60 * i)
Next i

' want to delete any FormatCondition intersecting
' with targetRange. loop through all FCs on sheet
' and delete if intersects.
Set targetRange = Sheets("Sheet1").Range("F3:F3")

For Each fc In s.Cells.FormatConditions
'MsgBox fc.AppliesTo.Address
If Not Intersect(fc.AppliesTo, targetRange) Is Nothing Then
' want to delete this FC but AppliesTo only works in XL2007
fc.AppliesTo.Select
End If
Next fc

' actually just trying to delete an individual
' formatcondition gives an 1004 error
s.Cells.FormatConditions(2).Delete

Has any one had any similar problems?
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Delete Individual FormatCondition gives 1004 Error

I think it need to decrement instead of increment

For i = Range("B6").FormatConditions.Count to 1 step -1
Range("B6").FormatConditions(i).Delete
Next i

"bsdz" wrote:

Hi

I am trying to search through FormatConditions in my Worksheet that
intersect with a target range and delete them. When I attempt to delete a
single FormatCondition I get a 1004 error.

In addition I am looking for equivalent functionality to Excel 2007's
FormatCondition's AppliesTo Property in Excel 2003 if any one has any
pointers.

A sample macro that demonstrates the deletion problem is below: -

Dim s As Worksheet
Set s = Sheets("Sheet1")

Dim fc As FormatCondition

' clear the entire sheet first
s.Cells.FormatConditions.Delete

' set up 3 overlapping ranges
' 1:5, 3:7, 5:9 = i*2-1:i*2+3
Dim ranges(1 To 3) As Range
Dim i As Integer
For i = 1 To 3
Set ranges(i) = s.Range(s.Cells(i * 2 - 1, i * 2 - 1), s.Cells(i * 2
+ 3, i * 2 + 3))
Set fc = ranges(i).FormatConditions.Add(xlExpression, xlEqual,
"=MOD(ROW()+16,2)0")
fc.Interior.Color = RGB(0, 0, 70 + 60 * i)
Next i

' want to delete any FormatCondition intersecting
' with targetRange. loop through all FCs on sheet
' and delete if intersects.
Set targetRange = Sheets("Sheet1").Range("F3:F3")

For Each fc In s.Cells.FormatConditions
'MsgBox fc.AppliesTo.Address
If Not Intersect(fc.AppliesTo, targetRange) Is Nothing Then
' want to delete this FC but AppliesTo only works in XL2007
fc.AppliesTo.Select
End If
Next fc

' actually just trying to delete an individual
' formatcondition gives an 1004 error
s.Cells.FormatConditions(2).Delete

Has any one had any similar problems?
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete Individual FormatCondition gives 1004 Error

Tbh that is what I tried first. If you look at the loop above my individual
deletion, that is where I need to delete the FormatCondition and that is
where I tried first. I suspect this is a bug in Excel. I will probably file
it with MS.

Thanks in any case :)

"Joel" wrote:

I think it need to decrement instead of increment

For i = Range("B6").FormatConditions.Count to 1 step -1
Range("B6").FormatConditions(i).Delete
Next i

"bsdz" wrote:

Hi

I am trying to search through FormatConditions in my Worksheet that
intersect with a target range and delete them. When I attempt to delete a
single FormatCondition I get a 1004 error.

In addition I am looking for equivalent functionality to Excel 2007's
FormatCondition's AppliesTo Property in Excel 2003 if any one has any
pointers.

A sample macro that demonstrates the deletion problem is below: -

Dim s As Worksheet
Set s = Sheets("Sheet1")

Dim fc As FormatCondition

' clear the entire sheet first
s.Cells.FormatConditions.Delete

' set up 3 overlapping ranges
' 1:5, 3:7, 5:9 = i*2-1:i*2+3
Dim ranges(1 To 3) As Range
Dim i As Integer
For i = 1 To 3
Set ranges(i) = s.Range(s.Cells(i * 2 - 1, i * 2 - 1), s.Cells(i * 2
+ 3, i * 2 + 3))
Set fc = ranges(i).FormatConditions.Add(xlExpression, xlEqual,
"=MOD(ROW()+16,2)0")
fc.Interior.Color = RGB(0, 0, 70 + 60 * i)
Next i

' want to delete any FormatCondition intersecting
' with targetRange. loop through all FCs on sheet
' and delete if intersects.
Set targetRange = Sheets("Sheet1").Range("F3:F3")

For Each fc In s.Cells.FormatConditions
'MsgBox fc.AppliesTo.Address
If Not Intersect(fc.AppliesTo, targetRange) Is Nothing Then
' want to delete this FC but AppliesTo only works in XL2007
fc.AppliesTo.Select
End If
Next fc

' actually just trying to delete an individual
' formatcondition gives an 1004 error
s.Cells.FormatConditions(2).Delete

Has any one had any similar problems?
Thanks

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
Calculate and display individual error bars for individual points del Charts and Charting in Excel 2 March 31st 06 05:11 PM
Calculate and display individual error bars for individual points del Charts and Charting in Excel 1 March 31st 06 04:24 AM
Simple For-Loop gives 1004 error using variable to EntireRow.Delete EdMX Excel Programming 3 December 2nd 04 02:43 AM
runtime error '1004' delete Method of Range Class Failed Tom Kennedy Excel Programming 0 April 14th 04 08:08 PM
runtime error '1004' delete Method of Range Class Failed Tom Ogilvy Excel Programming 0 April 1st 04 04:09 AM


All times are GMT +1. The time now is 03:01 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"