ich habe eine Personentabelle, wo mehrere Mitarbeiter ändern dürfen; dadurch werden manchmal Dropdowns, Filter, Formatierungen und vor allem Formeln "zerschossen". Durch mehrere Makros kann immer wieder ein Reorg. gemacht werden.
Jetzt müsste ich eine weitere Formel als Makro einbinden, welches in Spalte Z immer das aktuelle Alter anzeigt und es klappt leider nicht.
Formel: =WENN(H7="";"";DATEDIF(H7;HEUTE();"Y"))
Hier der Code:
Sub Reorg_BZL_Formeln()
Sheets("BZL").Select
'Es werden alle gefilterten Zeilen wieder eingeblendet
ActiveSheet.Unprotect "007"
With ActiveWorkbook.ActiveSheet
If .FilterMode Then
.ShowAllData
[A1].Select
End If
End With
'Es werden alle ausgeblendeten Spalten und Zeilen wieder eingeblendet.
Cells.Select
Selection.EntireColumn.Hidden = False
Selection.EntireRow.Hidden = False
Range("A1").Select
Dim rng As Range
Dim Loletzte&, x&, j&
Dim ersetzt As Boolean
Loletzte = Range("BZL_Ende").Row - 1 'im Namensnanager definiert
For j = 11 To 26 '11 = Spalte K bis Z (=26. Spalte)
If j = 12 Then j = 16 '12 = wenn Spalte 12(=L), springe zu Spalte 16 (=P)
If j = 17 Then j = 18 '17 = wenn Spalte 17(=Q), springe zu Spalte 18 (=R)
' neu ?
If j = 19 Then j = 26 '19 = wenn Spalte 19(=S), springe zu Spalte 26 (=Z)
For x = 7 To Loletzte 'ab Zeile 7 wird geprüft
If IsEmpty(Cells(x, j)) Then 'wenn Zelle leer, dann
Cells(x, j).Select 'Zelle wird markiert
'=WENN(J7="";"";WENN(J7=System!$S$9;"nein";"Fehler")))
If j = 11 Then Cells(x, j).FormulaLocal = "=WENN(" & Cells(x, j - 1).Address(0, 0) & "="""" _
;"""";WENN(" & Cells(x, j - 1).Address(0, 0) & "=System!$S$9;""nein"";""Fehler"")))"
'=WENN(N7="";"";WENN(O7="";N7;N7-O7))
If j = 16 Then Cells(x, j).FormulaLocal = "=WENN(" & Cells(x, j - 2).Address(0, 0) & "="""" _
;"""";WENN(" & Cells(x, j - 1).Address(0, 0) & "="""";" & Cells(x, j - 2).Address(0, 0) & ";" & Cells(x, j - 2).Address(0, 0) & "-" & Cells(x, j - 1).Address(0, 0) & "))"
'=WENN(N7="";"";WENN(O7="";1;WENN(O7=1;1;P7/N7)))
If j = 18 Then Cells(x, j).FormulaLocal = "=WENN(" & Cells(x, j - 4).Address(0, 0) & "="""" _
;"""";WENN(" & Cells(x, j - 3).Address(0, 0) & "="""";1;WENN(" & Cells(x, j - 3).Address(0, 0) & "=1;1;" & Cells(x, j - 2).Address(0, 0) & "/" & Cells(x, j - 4).Address(0, 0) & ")))"
'=WENN(H7="";"";DATEDIF(H7;HEUTE();"Y"))
If j = 26 Then Cells(x, j).FormulaLocal = "=WENN(" & Cells(x, j - 10).Address(0, 0) & "="" _
"";"""";datedif(" & Cells(x, j - 9).Address(0, 0) & "="""";1HEUTE();((""Y"")))"
If MsgBox("In " & Cells(x, j).Address(0, 0) & " wurde die fehlende Formel eingefügt:" _
& vbLf & vbLf & Cells(x, j).FormulaLocal & vbLf & vbLf & vbLf & "Weitersuchen?", vbYesNo) _
vbYes Then Exit Sub
ersetzt = True
End If
Next
Next
If ersetzt = False Then MsgBox "Formeln sind in allen drei Spalten vollständig vorhanden.", _
vbInformation, "Hinweis"
Range("A1").Select
End Sub
Die abgespeckte Datei hänge ich mal dran: https://www.herber.de/bbs/user/101541.xlsm
Wer kann mir bitte die Formel aus Spalte Z in das VBA einbauen?
Danke schon mal
Grüße - Erwin