Hallo zusammen
Ich habe das Problem, dass aufgrund ungenügender VBA-Kenntnisse meine Codes zu lang werden und ich es nicht hinkriege, diese mit intelligentem coden zu kürzen. :-)
Nachfolgend poste ich ein Beispiel eines Codes, nach welchem die Farbe unterschiedlicher Excel-Formen bestimmt werden soll. Das Schwierigkeit ist, dass es je nach Wert für die unterschiedlichen Formen eine unterschiedliche Einfärbung geben soll (5 Farbstufen/Preisstufen). Hat jemand von euch eine Idee, wie ich den folgenden Code kürzen könnte? Danke schon einmal.
'Form 1a
If Worksheets("Pivot_Planogramm").Range("BE6").Formula >= .Range("D31") And Worksheets("Pivot_Planogramm").Range("BE6") <= .Range("E31") And Worksheets("Code").Range("C4") = 1 Then
.Shapes("Form 1a").Fill.ForeColor.RGB = Range("F31").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BE6") >= .Range("D32") And Worksheets("Pivot_Planogramm").Range("BE6") <= .Range("E32") And Worksheets("Code").Range("C4") = 1 Then
.Shapes("Form 1a").Fill.ForeColor.RGB = Range("F32").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BE6") >= .Range("D33") And Worksheets("Pivot_Planogramm").Range("BE6") <= .Range("E33") And Worksheets("Code").Range("C4") = 1 Then
.Shapes("Form 1a").Fill.ForeColor.RGB = Range("F33").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BE6") >= .Range("D34") And Worksheets("Pivot_Planogramm").Range("BE6") <= .Range("E34") And Worksheets("Code").Range("C4") = 1 Then
.Shapes("Form 1a").Fill.ForeColor.RGB = Range("F34").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BE6") >= .Range("D35") And Worksheets("Pivot_Planogramm").Range("BE6") <= .Range("E35") And Worksheets("Code").Range("C4") = 1 Then
.Shapes("Form 1a").Fill.ForeColor.RGB = Range("F35").Interior.Color
Else
.Shapes("Form 1a").Fill.ForeColor.RGB = vbWhite
End If
'Form 1b
If Worksheets("Pivot_Planogramm").Range("BF6").Formula >= .Range("D31") And Worksheets("Pivot_Planogramm").Range("BF6") <= .Range("E31") Then
.Shapes("Form 1b").Fill.ForeColor.RGB = Range("F31").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BF6") >= .Range("D32") And Worksheets("Pivot_Planogramm").Range("BF6") <= .Range("E32") Then
.Shapes("Form 1b").Fill.ForeColor.RGB = Range("F32").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BF6") >= .Range("D33") And Worksheets("Pivot_Planogramm").Range("BF6") <= .Range("E33") Then
.Shapes("Form 1b").Fill.ForeColor.RGB = Range("F33").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BF6") >= .Range("D34") And Worksheets("Pivot_Planogramm").Range("BF6") <= .Range("E34") Then
.Shapes("Form 1b").Fill.ForeColor.RGB = Range("F34").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BF6") >= .Range("D35") And Worksheets("Pivot_Planogramm").Range("BF6") <= .Range("E35") Then
.Shapes("Form 1b").Fill.ForeColor.RGB = Range("F35").Interior.Color
Else
.Shapes("Form 1b").Fill.ForeColor.RGB = vbWhite
End If
'Form 1c
If Worksheets("Pivot_Planogramm").Range("BG6").Formula >= .Range("D31") And Worksheets("Pivot_Planogramm").Range("BG6") <= .Range("E31") Then
.Shapes("Form 1c").Fill.ForeColor.RGB = Range("F31").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BG6") >= .Range("D32") And Worksheets("Pivot_Planogramm").Range("BG6") <= .Range("E32") Then
.Shapes("Form 1c").Fill.ForeColor.RGB = Range("F32").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BG6") >= .Range("D33") And Worksheets("Pivot_Planogramm").Range("BG6") <= .Range("E33") Then
.Shapes("Form 1c").Fill.ForeColor.RGB = Range("F33").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BG6") >= .Range("D34") And Worksheets("Pivot_Planogramm").Range("BG6") <= .Range("E34") Then
.Shapes("Form 1c").Fill.ForeColor.RGB = Range("F34").Interior.Color
ElseIf Worksheets("Pivot_Planogramm").Range("BG6") >= .Range("D35") And Worksheets("Pivot_Planogramm").Range("BG6") <= .Range("E35") Then
.Shapes("Form 1c").Fill.ForeColor.RGB = Range("F35").Interior.Color
Else
.Shapes("Form 1c").Fill.ForeColor.RGB = vbWhite
End If
End With
|