I am new to VBA and I want to make an interactive map consisting of 10 districts, where each district would be colored, for example, green if person A is assigned to that district or red if person B is assigned to that district . I used this code from other threads and there is no error in the formula, but it seems like the shape color doesn't change. Can anyone tell me what is wrong in the code?
Private Sub Worksheet_Change(ByVal Target As Range)
For i = 1 To 10
If Sheet31.Cells(i, 2) = "Person A" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(237, 125, 49)
ElseIf Sheet31.Cells(i, 2) = "Person B" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(255, 192, 0)
ElseIf Sheet31.Cells(i, 2) = "Person C" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(91, 155, 23)
ElseIf Sheet31.Cells(i, 2) = "Person D" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(165, 165, 165)
ElseIf Sheet31.Cells(i, 2) = "Person E" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(96, 165, 165)
End If
Next i
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
For i = 1 To 10
If Sheet31.Cells(i, 2) = "Person A" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(237, 125, 49)
ElseIf Sheet31.Cells(i, 2) = "Person B" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(255, 192, 0)
ElseIf Sheet31.Cells(i, 2) = "Person C" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(91, 155, 23)
ElseIf Sheet31.Cells(i, 2) = "Person D" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(165, 165, 165)
ElseIf Sheet31.Cells(i, 2) = "Person E" Then
Sheet31.Shapes.Range(Array("Praha_" & i)).Fill.ForeColor.RGB = RGB(96, 165, 165)
End If
Next i
End Sub