AW: (WENN(UND))-Formel mit VBA
10.01.2014 15:27:51
fcs
Hallo Thomas,
eine VBA-Lösung kann wie folgt aussehen.
Die Aktualisierung der Daten ab Zelle I7 erfolgt dann auf Anforderung des Anwenders; z.B nach Ändern/Ergänzen von Daten in den Spalten C, D oder F
Hierzu im Tabellenblatt eine Schaltfläche aus den Formularsteuerelementen einfügen und dieser das Makro zuweisen.
Gruß
Franz
'Makro in einem allgemeinen Modul der Datei
Sub AktualisierenTerminuebersicht()
' Formeln Makro
Dim wks As Worksheet
Dim Zeile_L As Long, Spalte_L As Long
Dim Zeile_1 As Long, Spalte_1 As Long
Dim Zelle As Range, StatusCalc As Long
Set wks = ActiveWorkbook.Worksheets("Terminübersicht") ' - ggf. anpassen
'Makrobremsen lösen
With Application
StatusCalc = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
With wks
With .Range("I7") '1. Zelle mit Formel zur Berechnung von B/U/"" - ggf. anpassen
Zeile_1 = .Row
Spalte_1 = .Column
End With
'Letzte Datenspalte
Spalte_L = .Cells.Find(What:="*", after:=.Cells(1, 1), LookIn:=xlFormulas, _
lookat:=xlWhole, searchorder:=xlByColumns, Searchdirection:=xlPrevious).Column
'Letzte Datenzeile
Zeile_L = .Cells.Find(What:="*", after:=.Cells(1, 1), LookIn:=xlFormulas, _
lookat:=xlWhole, searchorder:=xlByRows, Searchdirection:=xlPrevious).Row
If Zeile_L >= Zeile_1 And Spalte_L >= Spalte_1 Then
'Altdaten löschen
With .Range(.Cells(Zeile_1, Spalte_1), .Cells(Zeile_L, Spalte_L))
.ClearContents
End With
End If
'Letzte Datenspalte
Spalte_L = .Cells.Find(What:="*", after:=.Cells(1, 1), LookIn:=xlFormulas, _
lookat:=xlWhole, searchorder:=xlByColumns, Searchdirection:=xlPrevious).Column
'Letzte Datenzeile
Zeile_L = .Cells.Find(What:="*", after:=.Cells(1, 1), LookIn:=xlFormulas, _
lookat:=xlWhole, searchorder:=xlByRows, Searchdirection:=xlPrevious).Row
If Zeile_L >= Zeile_1 And Spalte_L >= Spalte_1 Then
With .Range(.Cells(Zeile_1, Spalte_1), .Cells(Zeile_L, Spalte_L))
'Formel einfügen
'=WENN(I$5>=$C7;WENN(I$5=RC3,IF(R5C