|
-
May 5th, 2005, 10:59 AM
#1
Thread Starter
Hyperactive Member
Excel, get conditinal formatting font color in VBA
I have a spreadsheet in Excel that uses the conditional formatting formulas to set cell font colors when they exceed certain limits.
e.g. cells > x have their font color set to Blue.
I've been trying to read the individual cell font colors from within a VBA function, e.g.
Code:
Debug.Print rng.Font.Color
Debug.Print rng.Font.FontStyle
Debug.Print rng.Font.ColorIndex
Debug.Print rng.Interior.Color
But this doesn't seem to know about the conditional formatting changes,
i.e. it returns the basic, default color info for the cell.
Is the actual, current font color info, as seen by the user, discernable via code somewhere?
Thanks, DaveBo
Last edited by DaveBo; May 5th, 2005 at 03:53 PM.
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
May 5th, 2005, 11:12 AM
#2
Re: Excel, get conditinal formatting font color in VBA
The first thing you want to do, if you look for the coding of something in VBA, use the macro recorder to do it manually and look at the code created by this recording.
I created a conditional format and the recorder gave me this:
VB Code:
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="35"
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
End With
I hope you can take it from here
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
May 5th, 2005, 12:30 PM
#3
Thread Starter
Hyperactive Member
Re: Excel, get conditinal formatting font color in VBA
Opus, Thanks, that's good info.
It tells me about the formulas used, but it still doesn't tell me if the formulas have actually been tripped and any conditions set.
i.e. it isn't telling me the current color of the cell.
Thanks, DaveBo
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
May 5th, 2005, 01:21 PM
#4
Re: Excel, get conditinal formatting font color in VBA
That's correct, however you can check using VBA if the condition is met, and you can check all possible formattings. It seems like a long way but it's possible.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
May 5th, 2005, 04:05 PM
#5
Addicted Member
Re: Excel, get conditinal formatting font color in VBA
 Originally Posted by DaveBo
Is the actual, current font color info, as seen by the user, discernable via code somewhere?
Thanks, DaveBo
I'm sure there is, but you could also check to see if the condition is met.
e.g. If rgn > x then msgbox "This cell color has been changed"
Implying that if the condition is true, the cell certainly has changed color.
Just a workaround.
p.s. I think that's what the previous post meant. Sorry..
-
May 6th, 2005, 09:56 AM
#6
Thread Starter
Hyperactive Member
Re: Excel, get conditinal formatting font color in VBA
I tried actually reading and parsing the format condition formulas to recreate the calculations it would make and determine what it should have done,
however ...
the conditional formatting was set on a large range of cells, with relative addresses used, i.e. the formula for the target cell compared the cell contents in the same column as the target cell but at row 1 and the contents in the same row but at columns 3 & 4.
Works fine in the sheet, but when reading the formulas in VBA the relative cell addresses were inconsistent, sometimes they pointed to the the proper columns & rows, other times they were the original formulas without the addresses adjusted for "relativity".
Anyway, I gave up on that approach.
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|