PC Review


Reply
Thread Tools Rate Thread

Changing order of conditional formats

 
 
=?Utf-8?B?bWlrZWxlZTEwMQ==?=
Guest
Posts: n/a
 
      25th Jun 2007
Hello,
I have a rather large range of cells that have 3 conditional formats. I'd
like to change the order that the formats are applied. However, most of the
cells also have other "unconditional" formats, so simply making the changes
in one cell then copying/pasting formats would mean having to go back through
and manually change those. So, I'm looking for a way to change the order of
the formats in VBA. However, I'm getting stuck at, what should be, the very
end. I've been able to move the formatconditions object to a variable (as
near as I can tell, anyway), but then can't move the object from the variable
back to the formatconditions object. I've tried the add method and the
modify method, but both give me a runtime error. Below is snip of the code:

----------
Dim Wkbk As Workbook, Nme As String, rng As Range, Cl As Range
Dim Valhldr(1 To 3) As Object


Set Wkbk = ActiveWorkbook

Nme = "testrange"

Set rng = Wkbk.Names(Nme).RefersToRange

For Each Cl In rng
For i = 1 To 3
Set Valhldr(i) = Cl.FormatConditions(i)
Next i

For i = 1 To 3
Cl.FormatConditions(1).Delete
Next i

Cl.FormatConditions(1).Add = Valhldr(3)
Cl.FormatConditions(2).Add = Valhldr(1)
Cl.FormatConditions(3).Add = Valhldr(2)

Next Cl
--------------------

So, if anyone has any suggestions on how I can move the formats from the
variable back to the formatconditions, or has another suggestion on how I can
do this, I'd really appreciate it. The conditions themselves are rather
complex formulas. Hardcoding them is an option, but figured I'd see if this
could work.

Thanks to all.


--
Mike Lee
McKinney,TX USA
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      25th Jun 2007
Why are you deleting and then adding. Whhy not just modify the values?


Dim Wkbk As Workbook, Nme As String, rng As Range, Cl As Range
Dim Valhldr(1 To 3) As Object


Set Wkbk = ActiveWorkbook

Nme = "testrange"

Set rng = Wkbk.Names(Nme).RefersToRange

For Each Cl In rng

Valhldr(1) = Cl.FormatConditions.formula1
Valhldrcolor(1) = Cl.FormatConditions.color.index
Valhldr(2) = Cl.FormatConditions.formula2
Valhldrcolor(2) = Cl.FormatConditions.color.index
Valhldr(3) = Cl.FormatConditions.formula3
Valhldrcolor(3) = Cl.FormatConditions.color.index

Cl.FormatConditions(1).Modify xlCellValue, xlEqual, Valhldr(3)
Cl.FormatConditions(1).interior.color.index = Valhldrcolor(3)
Cl.FormatConditions(2).Modify xlCellValue, xlEqual, Valhldr(1)
Cl.FormatConditions(2).interior.color.index = Valhldrcolor(1)
Cl.FormatConditions(3).Modify xlCellValue, xlEqual, Valhldr(2)
Cl.FormatConditions(3).interior.color.index = Valhldrcolor(2)

>
> Next Cl


"mikelee101" wrote:

> Hello,
> I have a rather large range of cells that have 3 conditional formats. I'd
> like to change the order that the formats are applied. However, most of the
> cells also have other "unconditional" formats, so simply making the changes
> in one cell then copying/pasting formats would mean having to go back through
> and manually change those. So, I'm looking for a way to change the order of
> the formats in VBA. However, I'm getting stuck at, what should be, the very
> end. I've been able to move the formatconditions object to a variable (as
> near as I can tell, anyway), but then can't move the object from the variable
> back to the formatconditions object. I've tried the add method and the
> modify method, but both give me a runtime error. Below is snip of the code:
>
> ----------
> Dim Wkbk As Workbook, Nme As String, rng As Range, Cl As Range
> Dim Valhldr(1 To 3) As Object
>
>
> Set Wkbk = ActiveWorkbook
>
> Nme = "testrange"
>
> Set rng = Wkbk.Names(Nme).RefersToRange
>
> For Each Cl In rng
> For i = 1 To 3
> Set Valhldr(i) = Cl.FormatConditions(i)
> Next i
>
> For i = 1 To 3
> Cl.FormatConditions(1).Delete
> Next i
>
> Cl.FormatConditions(1).Add = Valhldr(3)
> Cl.FormatConditions(2).Add = Valhldr(1)
> Cl.FormatConditions(3).Add = Valhldr(2)
>
> Next Cl
> --------------------
>
> So, if anyone has any suggestions on how I can move the formats from the
> variable back to the formatconditions, or has another suggestion on how I can
> do this, I'd really appreciate it. The conditions themselves are rather
> complex formulas. Hardcoding them is an option, but figured I'd see if this
> could work.
>
> Thanks to all.
>
>
> --
> Mike Lee
> McKinney,TX USA

 
Reply With Quote
 
=?Utf-8?B?bWlrZWxlZTEwMQ==?=
Guest
Posts: n/a
 
      25th Jun 2007
ahhh...i was trying to move the entire object instead of breaking it down
into it's individual components.

thanks for the insight.

--
Mike Lee
McKinney,TX USA


"Joel" wrote:

> Why are you deleting and then adding. Whhy not just modify the values?
>
>
> Dim Wkbk As Workbook, Nme As String, rng As Range, Cl As Range
> Dim Valhldr(1 To 3) As Object
>
>
> Set Wkbk = ActiveWorkbook
>
> Nme = "testrange"
>
> Set rng = Wkbk.Names(Nme).RefersToRange
>
> For Each Cl In rng
>
> Valhldr(1) = Cl.FormatConditions.formula1
> Valhldrcolor(1) = Cl.FormatConditions.color.index
> Valhldr(2) = Cl.FormatConditions.formula2
> Valhldrcolor(2) = Cl.FormatConditions.color.index
> Valhldr(3) = Cl.FormatConditions.formula3
> Valhldrcolor(3) = Cl.FormatConditions.color.index
>
> Cl.FormatConditions(1).Modify xlCellValue, xlEqual, Valhldr(3)
> Cl.FormatConditions(1).interior.color.index = Valhldrcolor(3)
> Cl.FormatConditions(2).Modify xlCellValue, xlEqual, Valhldr(1)
> Cl.FormatConditions(2).interior.color.index = Valhldrcolor(1)
> Cl.FormatConditions(3).Modify xlCellValue, xlEqual, Valhldr(2)
> Cl.FormatConditions(3).interior.color.index = Valhldrcolor(2)
>
> >
> > Next Cl

>
> "mikelee101" wrote:
>
> > Hello,
> > I have a rather large range of cells that have 3 conditional formats. I'd
> > like to change the order that the formats are applied. However, most of the
> > cells also have other "unconditional" formats, so simply making the changes
> > in one cell then copying/pasting formats would mean having to go back through
> > and manually change those. So, I'm looking for a way to change the order of
> > the formats in VBA. However, I'm getting stuck at, what should be, the very
> > end. I've been able to move the formatconditions object to a variable (as
> > near as I can tell, anyway), but then can't move the object from the variable
> > back to the formatconditions object. I've tried the add method and the
> > modify method, but both give me a runtime error. Below is snip of the code:
> >
> > ----------
> > Dim Wkbk As Workbook, Nme As String, rng As Range, Cl As Range
> > Dim Valhldr(1 To 3) As Object
> >
> >
> > Set Wkbk = ActiveWorkbook
> >
> > Nme = "testrange"
> >
> > Set rng = Wkbk.Names(Nme).RefersToRange
> >
> > For Each Cl In rng
> > For i = 1 To 3
> > Set Valhldr(i) = Cl.FormatConditions(i)
> > Next i
> >
> > For i = 1 To 3
> > Cl.FormatConditions(1).Delete
> > Next i
> >
> > Cl.FormatConditions(1).Add = Valhldr(3)
> > Cl.FormatConditions(2).Add = Valhldr(1)
> > Cl.FormatConditions(3).Add = Valhldr(2)
> >
> > Next Cl
> > --------------------
> >
> > So, if anyone has any suggestions on how I can move the formats from the
> > variable back to the formatconditions, or has another suggestion on how I can
> > do this, I'd really appreciate it. The conditions themselves are rather
> > complex formulas. Hardcoding them is an option, but figured I'd see if this
> > could work.
> >
> > Thanks to all.
> >
> >
> > --
> > Mike Lee
> > McKinney,TX USA

 
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
Conditional Formats, how to scroll and view all formats? Bill E Microsoft Excel Worksheet Functions 0 12th May 2010 07:58 PM
Conditional formats unexpectedly changing Blue Max Microsoft Excel Discussion 1 8th Mar 2009 11:20 AM
Conditional formats- paste special formats? =?Utf-8?B?amNhcm5leQ==?= Microsoft Excel Misc 1 1st Nov 2007 06:37 PM
paste conditional formats as formats =?Utf-8?B?bGVv?= Microsoft Excel Misc 2 5th Jul 2007 10:06 AM
Excel, how to copy conditional formats in sequential order 1,2,3 =?Utf-8?B?U2hvRGFu?= Microsoft Excel Worksheet Functions 6 3rd Jul 2007 01:54 PM


Features
 

Advertising
 

Newsgroups
 


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