Question

I've written an Excel-macro to sort and highlight data with conditioned formatting

=$A1=TODAY() => use yellow font

When I wrote it in 2007 and executed it in 2010 it made the $A 1 to 6 or something. After rewriting it 2010 it works fine in 2010 but when executed in 2007 it uses 1048572 (1024 * 1024 - 4) I guess it is some sort of arithmetic overflow.

I double checked the source code and that seems to be okay, saying "$A1" in all the right places. It just doesn't do as it says there.

Is there a difference in the compiler or 2010 using double quotes where 2007 uses single or anything?

EDIT:

Selection.FormatConditions(1).StopIfTrue = False
Cells.FormatConditions.Delete
Columns("A:S").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$A1=HEUTE()"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

I blame it on the fourth line. HEUTE() is TODAY()

Was it helpful?

Solution

I think its some weird behavior of excel 2007:

If you set format conditions with vba it sets all ranges relative to the active cell, so if C3 is the active cell a C3 in the formula becomes a A1 (a D3 a B1)

the following may help (after Columns("A:S").Select)

Range("A1").Activate
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top