I have an old macro that was working fine on Excel 2003 but creates issues with Excel 2010. The part that causes problems is:
If Not IsNull(someRange.FormatConditions(parActiveCondition).Interior.Color) Then
locVisibleColor = someRange.FormatConditions(parActiveCondition).Interior.Color
End if
where parActiveCondition
is the active conditional formatting number on someRange
.
When the background is selected as "No Color", someRange.FormatConditions(parActiveCondition).Interior.Color
returns
Null
in Excel 2003 The problem is that a black background also returns 0. So in Excel 2010 it seems no longer possible to make the difference between a black background and no background color.
Does anybody know a workaround?
ps: I could obviously select a white background instead of "No Color" but I'd rather not change all the spreadsheets and conditional formatting rules.
You could use a Boolean secondary check such as
IsNull(someRange.FormatConditions(parActiveCondition).Interior.ColorIndex) 'or
IsNull(someRange.FormatConditions(parActiveCondition).Interior.TintAndShade)
when
.FormatConditions(parActiveCondition).Interior.Color = 0
Option Explicit
Sub test()
Dim Color
Dim R As Integer
Dim G As Integer
Dim B As Integer
Color = ThisWorkbook.Sheets(1).Range("A1").Interior.Color
R = Color Mod 256
G = (Color \ 256) Mod 256
B = (Color \ 256 \ 256) Mod 256
ThisWorkbook.Sheets(1).Range("B1").Interior.Color = RGB(R, G, B)
End Sub
Black returns (0,0,0)
It appears however that "no color" returns (255,255,255) (=white)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.