ich brauch mal wieder Eure Mithilfe.
In dem maximal C58:P63 umfassenden Bereich möchte ich mittels folgender Function
dynamisch Formeln nach diesem Schema generieren:
=WENN($AC$36=0;SUMME(C4:C9)*24;SUMME(C4:C9))
Hier die Function:
Public Sub Wochensummen()
Dim byt_Zeile, byt_Spalte As Byte
Dim int_WoA, int_WoE, int_test As Integer
Dim str_TeilFormel, str_Formel As String
' On Error GoTo HandleError
' Application.DisplayAlerts = False
byt_Zeile = 58
While Cells(byt_Zeile, 1).Value ""
MsgBox ("Zeile:" + Str(byt_Zeile)) ' Debug-Ausgabe: aktuelle Zeile
'=WENN(TAG(B58)>34;"";TAG(B58)+3)
int_WoA = Day(Cells(byt_Zeile, 2).Value) + 3
MsgBox ("1. Zeile: " + Str(int_WoA)) ' Debug-Ausgabe: dynamisch ermittelter Index der 1. _
Summenzeile
'=WENN(TAG(B58)+10>34;34;TAG(B58+7)+2-WOCHENTAG(B58+7;3))
int_test = Day(Cells(byt_Zeile, 2).Value) + 10
If int_test > 34 Then
int_WoE = 34
Else
int_WoE = Day(Cells(byt_Zeile, 2).Value) + 9 - Weekday(Cells(byt_Zeile, 2).Value, _
vbTuesday)
End If
MsgBox ("x. Zeile: " + Str(int_WoE)) ' Debug-Ausgabe: dynamisch ermittelter Index der _
letzten Summenzeile
For byt_Spalte = 3 To 16
str_TeilFormel = "=SUM(" & Chr(64 + byt_Spalte) & "[" & Str(int_WoA) & "]:" & Chr( _
64 + byt_Spalte) & "[" & Str(int_WoE) & "])"
MsgBox ("TeilFormel: " + str_TeilFormel) ' Debug-Ausgabe: Teilformel
'=WENN($AC$36=0;SUMME(C4:C9)*24;SUMME(C4:C9))
str_Formel = "=IF($AC$36=0;" & str_TeilFormel & "*24;" & str_TeilFormel & ")"
MsgBox ("Formel: " + str_Formel) ' Debug-Ausgabe: Endformel
' UND HIER KRACHT ES JETZT
Cells(byt_Zeile, byt_Spalte).FormulaR1C1 = str_Formel
' UND ICH KOMM NICHT DRAUF, WARUM
Next
byt_Zeile = byt_Zeile + 1
Wend
' Application.DisplayAlerts = True
' Exit Sub
'HandleError:
' Call ErrHandler("[frm_Sheetformat] Sub Wochensummen()")
' Resume Next
End Sub
In der abgesetzten Codezeile, wo ich die generierte Formel zuweisen möchte, kracht's mit einem Laufzeitfehler 1004.
Ich hab grad ne Denkblockade und komme nicht weiter.
Wäre super, wenn mir hier jemand auf die Sprünge helfen könnte.
Danke,
Roland