There are two FOR EACH loops in the code below. The first FOR loop cycles through the first array (shape 1,shape 2 ,shape 3).The second FOR loop cycles through the second array (0.3, 0.4, 0.5).
Shape 1 0.3
Shape 2 0.4
Shape 3 0.5
The second FOR loop colors the shape on my worksheet based on the value of second array. The problem is all of my shapes are being colored with first value (i.e 0.3). I want Shape 1 to be colored based on 0.3 , Shape 2 based on 0.4 and so on. Thanks for helping me with this.
Private Sub Worksheet_Calculate()
Dim arr1
Dim arr2
Set arr1 = Worksheets("Sheet2").Range("valueforarr1")
Set arr2 = Worksheets("Sheet2").Range("Valueforarr2")
Dim c, d As Range
For Each c In arr1
c = Replace(c, " ", "_")
MsgBox c
For Each d In arr2
If d >= 0.2 And d <= 0.3 Then
Worksheets("Sheet1").Shapes(c).Fill.ForeColor.RGB = RGB(237, 247, 249)
Exit For
ElseIf d > 0.3 And d <= 0.4 Then
Worksheets("Sheet1").Shapes(c).Fill.ForeColor.RGB = RGB(218, 238, 243)
Exit For
ElseIf d > 0.4 And d <= 0.5 Then
Worksheets("Sheet1").Shapes(c).Fill.ForeColor.RGB = RGB(183, 222, 232)
Exit For
ElseIf d > 0.5 Then
Worksheets("Sheet1").Shapes(c).Fill.ForeColor.RGB = RGB(146, 205, 220)
Exit For
ElseIf d Is Nothing Then
Worksheets("Sheet1").Shapes(c).Fill.ForeColor.RGB = RGB(255, 255, 255)
Exit For
End If
Next d
Next c
End Sub