Quelcode in ein macro einbinden
Hallo Profis
kann mir bitte einer diesen Code so verändern das ich den einfach als Makro in ein Button einfügen kann.
Private Sub Worksheet_Change( _
ByVal Target As Excel.Range)
If Intersect(Target, Range("C5:C21")) _
Is Nothing Then Exit Sub
If Target.Value = "Test" Then
Target.Interior.ColorIndex = 4
Target.Font.ColorIndex = 1
End If
If Target.Value = "%" Then
Target.Interior.ColorIndex = 54
Target.Font.ColorIndex = 1
End If
If Target.Value = "K" Then
Target.Interior.ColorIndex = 10
Target.Font.ColorIndex = 1
End If
If Target.Value = "2" Then
Target.Interior.ColorIndex = 27
Target.Font.ColorIndex = 1
End If
If Target.Value = "3" Then
Target.Interior.ColorIndex = 14
Target.Font.ColorIndex = 1
End If
If Target.Value = "A" Then
Target.Interior.ColorIndex = 48
Target.Font.ColorIndex = 1
End If
If Target.Value = "R" Then
Target.Interior.ColorIndex = 35
Target.Font.ColorIndex = 1
End If
If Target.Value = "$" Then
Target.Interior.ColorIndex = 9
Target.Font.ColorIndex = 1
End If
If Target.Value = "L" Then
Target.Interior.ColorIndex = 23
Target.Font.ColorIndex = 1
End If
If Target.Value = "II" Then
Target.Interior.ColorIndex = 27
Target.Font.ColorIndex = 1
End If
If Target.Value = "III" Then
Target.Interior.ColorIndex = 14
Target.Font.ColorIndex = 1
End If
If Target.Value = "" Then
Target.Interior.ColorIndex = 2
End If
End Sub
Habe mir diesen Code über google beschaffen der tut es auch einwandfrei. leider nur dann wen ich den in die Arbeitsmappe einfüge. das Problem dabei ich habe 30 von diesen und in jeder soll das gemacht werden. jeder kann sich vorstellen was es heißt falls da mal Änderungen vorgenommen werden müssen
Antwort schreiben
Antwort 1 von Hajo_Zi vom 08.01.2019, 14:01 Options
Hallo Namensloser,
Option Explicit
Private Sub CommandButton1_Click()
Dim RaZelle As Range
For Each RaZelle In Range("C5:C21")
With RaZelle
Select Case .Value
Case "Test"
.Interior.ColorIndex = 4
.Font.ColorIndex = 1
Case "%"
.Interior.ColorIndex = 54
.Font.ColorIndex = 1
Case "K"
.Interior.ColorIndex = 10
.Font.ColorIndex = 1
Case 2, "II"
.Interior.ColorIndex = 27
.Font.ColorIndex = 1
Case 3, "III"
.Interior.ColorIndex = 14
.Font.ColorIndex = 1
Case "A"
.Interior.ColorIndex = 48
.Font.ColorIndex = 1
Case "R"
.Interior.ColorIndex = 35
.Font.ColorIndex = 1
Case "$"
.Interior.ColorIndex = 9
.Font.ColorIndex = 1
Case "L"
.Interior.ColorIndex = 23
.Font.ColorIndex = 1
Case ""
.Interior.ColorIndex = 2
End Select
End With
Next RaZelle
End Sub
Gruß Hajo