FiniteMonkeys
Technical User
I'm trying to modify a bit of Excel code to work with dynamically referenced locations, and I'm stumped.
Here is the working code with non-dynamic referencing. You start by selecting a range of cells (say A1:C3), then run this code to conditionally bold some of the cells in the selected range based on the values found in an a second different range of cells (in this case, the equivelently shaped 3 by 3 block of cells starting with E1 at the top right corner). Here is the working code:
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E1<0.05"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
The problem is that I would like to dynamically assign the cell address in this code using a value that I calculate elsewhere. But if I start rewriting this as:
"MyLocation = E2
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=MyLocation <0.05"
...
"
It interprets "MyLocation" as a literal value, not as a variable to interpolate. I've tried messing with adding more quote marks, but I can't make it work.
Help?
Alex
Here is the working code with non-dynamic referencing. You start by selecting a range of cells (say A1:C3), then run this code to conditionally bold some of the cells in the selected range based on the values found in an a second different range of cells (in this case, the equivelently shaped 3 by 3 block of cells starting with E1 at the top right corner). Here is the working code:
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=E1<0.05"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
The problem is that I would like to dynamically assign the cell address in this code using a value that I calculate elsewhere. But if I start rewriting this as:
"MyLocation = E2
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=MyLocation <0.05"
...
"
It interprets "MyLocation" as a literal value, not as a variable to interpolate. I've tried messing with adding more quote marks, but I can't make it work.
Help?
Alex