я новичок в VBA, только что начал в маленьком проекте, где у меня есть 427 фигур, каждая фигура будет меняться в соответствии с соответствующим числом, введенным в ячейку, все работало до тех пор, пока не обошло форму 100+, где написано «процедура большая", может кто-нибудь помочь мне обойтись, я пытаюсь проверить использование sub, но не могу заставить его работать.
Большое спасибо
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("W1")) Is Nothing Then
Me.Shapes("001").Select
With Range("W1")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W2")) Is Nothing Then
Me.Shapes("002").Select
With Range("W2")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W3")) Is Nothing Then
Me.Shapes("003").Select
With Range("W3")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W4")) Is Nothing Then
Me.Shapes("004").Select
With Range("W4")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W5")) Is Nothing Then
Me.Shapes("005").Select
With Range("W5")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W6")) Is Nothing Then
Me.Shapes("006").Select
With Range("W6")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W7")) Is Nothing Then
Me.Shapes("007").Select
With Range("W7")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W8")) Is Nothing Then
Me.Shapes("008").Select
With Range("W8")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W9")) Is Nothing Then
Me.Shapes("009").Select
With Range("W9")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W10")) Is Nothing Then
Me.Shapes("010").Select
With Range("W10")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W11")) Is Nothing Then
Me.Shapes("011").Select
With Range("W11")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W12")) Is Nothing Then
Me.Shapes("012").Select
With Range("W12")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W13")) Is Nothing Then
Me.Shapes("013").Select
With Range("W13")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W14")) Is Nothing Then
Me.Shapes("014").Select
With Range("W14")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W15")) Is Nothing Then
Me.Shapes("015").Select
With Range("W15")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W16")) Is Nothing Then
Me.Shapes("016").Select
With Range("W16")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W17")) Is Nothing Then
Me.Shapes("017").Select
With Range("W17")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W18")) Is Nothing Then
Me.Shapes("018").Select
With Range("W18")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W19")) Is Nothing Then
Me.Shapes("019").Select
With Range("W19")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W20")) Is Nothing Then
Me.Shapes("020").Select
With Range("W20")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W21")) Is Nothing Then
Me.Shapes("021").Select
With Range("W21")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W22")) Is Nothing Then
Me.Shapes("022").Select
With Range("W22")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W23")) Is Nothing Then
Me.Shapes("023").Select
With Range("W23")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W24")) Is Nothing Then
Me.Shapes("024").Select
With Range("W24")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W25")) Is Nothing Then
Me.Shapes("025").Select
With Range("W25")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W26")) Is Nothing Then
Me.Shapes("026").Select
With Range("W14")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W27")) Is Nothing Then
Me.Shapes("027").Select
With Range("W27")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W28")) Is Nothing Then
Me.Shapes("028").Select
With Range("W28")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W29")) Is Nothing Then
Me.Shapes("029").Select
With Range("W29")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W30")) Is Nothing Then
Me.Shapes("030").Select
With Range("W30")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W31")) Is Nothing Then
Me.Shapes("031").Select
With Range("W31")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W32")) Is Nothing Then
Me.Shapes("032").Select
With Range("W32")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W33")) Is Nothing Then
Me.Shapes("033").Select
With Range("W33")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W34")) Is Nothing Then
Me.Shapes("034").Select
With Range("W34")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W35")) Is Nothing Then
Me.Shapes("035").Select
With Range("W35")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W36")) Is Nothing Then
Me.Shapes("036").Select
With Range("W36")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W37")) Is Nothing Then
Me.Shapes("037").Select
With Range("W37")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W38")) Is Nothing Then
Me.Shapes("038").Select
With Range("W38")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W39")) Is Nothing Then
Me.Shapes("039").Select
With Range("W39")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W40")) Is Nothing Then
Me.Shapes("040").Select
With Range("W40")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W41")) Is Nothing Then
Me.Shapes("041").Select
With Range("W41")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W42")) Is Nothing Then
Me.Shapes("042").Select
With Range("W42")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W43")) Is Nothing Then
Me.Shapes("043").Select
With Range("W43")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W44")) Is Nothing Then
Me.Shapes("044").Select
With Range("W44")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W45")) Is Nothing Then
Me.Shapes("045").Select
With Range("W45")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W46")) Is Nothing Then
Me.Shapes("046").Select
With Range("W46")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W47")) Is Nothing Then
Me.Shapes("047").Select
With Range("W47")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W48")) Is Nothing Then
Me.Shapes("048").Select
With Range("W48")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W49")) Is Nothing Then
Me.Shapes("049").Select
With Range("W49")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If
If Not Intersect(Target, Range("W50")) Is Nothing Then
Me.Shapes("050").Select
With Range("W50")
If .Value > 0 And .Value <= 56 Then
Selection.ShapeRange.Fill.ForeColor.RGB = ThisWorkbook.Colors(.Value)
Else
Selection.ShapeRange.Fill.ForeColor.RGB = 0
End If
.Select
End With
End If