AW: formelwerte überprüfen
01.01.2025 18:54:02
Ironlucky
Danke für eure Hilfe, hatte da ein Brett vorm Kopf.
in der Zelle steht ja für excel ne unformatierte Zahl also musste meine Abfrage mit "KW 52" logischerweise Nothing ergeben. Hier mal mein Code der läuft wie er soll.
Private Sub Worksheet_Activate()
Dat = Evaluate("Datum")
Dim rngCell As Range
Dim strText As String
strText = "52"
For Each rngCell In Range("I359:I369")
If rngCell.Value = strText Then
Exit Sub
End If
Next rngCell
If Evaluate("Schreiben") = 0 Then
Worksheets("Vorlage (2)").Unprotect
Range("A5") = Dat
For z = 0 To 364
ndat = Dat + z
If Sonntag(ndat) Or Samstag(ndat) Or Feiertag(ndat) Then
Range(Cells(5 + z, 1), Cells(5 + z, 7)).Interior.ColorIndex = 6
Range(Cells(5 + z, 11), Cells(5 + z, 18)).Interior.ColorIndex = 6
End If
Next z
If Range("A5") = Dat Then
For x = 0 To 7
If Cells(5 + x, 8) = 7 Then
Cells(5 + x, 19).Select
If x = 6 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-6]C[-1]:RC[-1])"
ElseIf x = 5 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-5]C[-1]:RC[-1])"
ElseIf x = 4 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-4]C[-1]:RC[-1])"
ElseIf x = 3 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-3]C[-1]:RC[-1])"
ElseIf x = 2 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C[-1]:RC[-1])"
ElseIf x = 1 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-1C[-1]:RC[-1])"
End If
Cells(5 + x, 10).Select
If x = 6 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-6]C[-3]:RC[-3])/24"
ElseIf x = 5 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-5]C[-3]:RC[-3])/24"
ElseIf x = 4 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-4]C[-3]:RC[-3])/24"
ElseIf x = 3 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-3]C[-3]:RC[-3])/24"
ElseIf x = 2 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C[-3]:RC[-3])/24"
ElseIf x = 1 Then
ActiveCell.FormulaR1C1 = "=SUM(R[-1C[-3]:RC[-3])/24"
End If
Exit For
End If
Next x
End If
l = 6 + x
s = 365 - x
For a = 0 To s
If Cells(l + a, 8) = 7 Then
Cells(l + a, 19).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-6]C[-1]:RC[-1])"
Cells(l + a, 10).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-6]C[-3]:RC[-3])/24"
End If
Next a
Worksheets("Einstell.").Unprotect
Evaluate("Schreiben") = 1
ActiveSheet.Cells(1, 8) = 1
Worksheets("Einstell.").Protect
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub