nathan2314
07-07-2008, 02:25 PM
:hi: hello all,
I'm trying to run a for loop and have the index combined with a string (either x or y) to loop through a bunch of number values and compare x1 with y1, x2 with y2, x3 with y3 etc...Then I want x line in my graph I have to turn red if x drops below the y line (that is the x < y for the values i'm comparing as the loop iterates.
For i = 1 To 4
val1 = CStr("x" & i)
val2 = CStr("y" & i)
If val1 < val2 Then
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 3
.Shadow = False
End With
End If
Next i
The problem is that when I use the cstr() to combine x or y to the index, it ends up comparing for example "x1" < "y1". The variables x1 and y1 have already been assigned values earlier in the code. But in the loop it doesn't resolve x1 and y1 but compares just as strings. How can i get the strings x1, y1 to resolve to the variable values??
I'm trying to run a for loop and have the index combined with a string (either x or y) to loop through a bunch of number values and compare x1 with y1, x2 with y2, x3 with y3 etc...Then I want x line in my graph I have to turn red if x drops below the y line (that is the x < y for the values i'm comparing as the loop iterates.
For i = 1 To 4
val1 = CStr("x" & i)
val2 = CStr("y" & i)
If val1 < val2 Then
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 3
.Shadow = False
End With
End If
Next i
The problem is that when I use the cstr() to combine x or y to the index, it ends up comparing for example "x1" < "y1". The variables x1 and y1 have already been assigned values earlier in the code. But in the loop it doesn't resolve x1 and y1 but compares just as strings. How can i get the strings x1, y1 to resolve to the variable values??