Mit untenstehendem Makro Fülle ich Zellen mit Farbe und Buchstaben, in Abhänigkeit von einem Code (ein "X") in verschiedenen Zeilen und der Ortschaft die in einer Spalte steht, in mehrere Tabellenblätter ab. Dabei darf keine Zelle überschrieben werden, die den Farbindex = 20 hat.
Das Makro funktioniert eigentlich. Nur braucht der Rechner mit voller CPU-Auslastung relativ lange bis das Makro durchgelaufen ist.
Was kann ich ändern damit das Makro schneller läuft, oder braucht diese Funktion einfach seine Zeit?
Für eure Antwort danke ich bestens.
Roland
Sub Zellenfärben()
Dim Zelle As Range
Dim i As Integer
Dim Bereich As Range
Application.ScreenUpdating = False
For i = 1 To Worksheets.Count - 5
Worksheets(i).Activate
ActiveSheet.Unprotect myPwd
Set Bereich = Range("F6:BO" & Cells(Rows.Count, 4).End(xlUp).Row)
Bereich.Select
With Selection
For Each Zelle In Selection
If Not .Interior.ColorIndex = 20 Then
If Cells(207, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Aarau" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(208, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Bellinzona" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(209, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Bern" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(216, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Conthey" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(209, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Fraubrunnen" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(216, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Glis" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(209, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Ins" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(209, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Ittigen" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(210, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Luzern" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(211, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Nyon" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(217, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Ohringen" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(212, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Sargans" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(213, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Sissach" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(214, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "St. Gallen" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(215, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "St-Imier" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
If Not .Interior.ColorIndex = 20 Then
If Cells(218, Zelle.Column) = "X" And Cells(Zelle.Row, 4) = "Zürich" Then
Zelle.Interior.ColorIndex = 40
Zelle.Value = "R"
End If
End If
Next
End With
Range("A5").Select
ActiveSheet.Protect myPwd
Next i
Application.ScreenUpdating = True
End Sub