Hallo,
ich will Laufzeiten von Projektphasen in einer Exceltabelle darstellen.
Über die UserForm gebe ich mittels DT-Picker mein Datum für den Beginn und mein Datum für das Ende der Phase ein.
Dann sollen in meiner Tabelle die Zellen ab Beginn bis Ende markiert werden (die Zellen haben alle ein Datum hinterlegt)
Ich brauche sozusagen eine Funktion, die mir die Dauer einer Phase in Tagen ausrechnet, Bsp. BerechneLaufzeit()
Dann brauch ich eine Suchfunktion, die mir mein bestimmtes Datum in der bestimmten Zelle findet und dann so viele Zellen "einfärbt"
wie ich Tage in meiner BerechneLaufzeit() -Funktion ausgerechnet habe.
Das wäre meine Idee dazu. Falls jmd eine bessere Idee hat dann bin ich für Neues offen.
Ich hab einige Ansätze und Varianten probiert und bereits einige Codes ausprobiert, diese funktionieren aber leider nicht. Ich weiß auch nicht wo mein Fehler ist....
Varante 1:
Public VonA As Variant, BisA As Variant
Public VonB As Variant, BisB As Variant
Public VonC As Variant, BisC As Variant
Private Sub Datum_VON_A_Exit_Exit(ByVal Cancel As MSForms.ReturnBoolean) 'Avon
VonA = Datum_VON_A_Exit.Value
End Sub
Private Sub Datum_BIS_A_Exit(ByVal Cancel As MSForms.ReturnBoolean) 'Abis
BisA = Datum_BIS_A.Value
End Sub
Private Sub Datum_VON_B_Exit(ByVal Cancel As MSForms.ReturnBoolean) 'Bvon
VonB = Datum_VON_B.Value
End Sub
Private Sub Datum_BIS_B_Exit(ByVal Cancel As MSForms.ReturnBoolean) 'Bbis
BisB = Datum_BIS_B.Value
End Sub
Private Sub Datum_VON_C_Exit(ByVal Cancel As MSForms.ReturnBoolean) 'Cvon
VonC = Datum_VON_C.Value
End Sub
Private Sub Datum_BIS_C_Exit(ByVal Cancel As MSForms.ReturnBoolean) 'Cbis
BisC = Datum_BIS_C.Value
End Sub
(...)
ActiveSheet.Cells.FormatConditions.Delete
If VonA <> "" Or BisA <> "" Then
With ActiveSheet.Range("E6:XFD6") 'A
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=UND(E6>=DATWERT(""" & VonA & """);E6<=DATWERT(""" & BisA & """))"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
End With
End With
End If
If VonB <> "" Or BisB <> "" Then
With ActiveSheet.Range("E8:XFD8") 'B
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=UND(E6>=DATWERT(""" & VonB & """);E6<=DATWERT(""" & BisB & """))"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
End With
End With
End If
If VonC <> "" Or BisC <> "" Then
With ActiveSheet.Range("E9:XFD9") 'C
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=UND(E6>=DATWERT(""" & VonC & """);E6<=DATWERT(""" & BisC & """))"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
End With
End With
End If
(...)
Variante 2:
Dim Zeile As Range
Dim Spalte As Variant
Zeile = 4
For Spalte = 5 To 4390
Dim datumgegeben As Date
Dim datumgesucht As Date
datumgegeben = Format(UserForm1.Datum_PunktA, "h:mm:ss")
datumgesucht = Format(Worksheets("Tabelle1").Cells(Zeile, Spalte), "h:mm:ss")
If datumgegeben = datumgesucht Then
Worksheets("Tabelle1").Cells(Zeile, Spalte).Interior.Color = 255
End If
Next
Bin leider nicht ganz so fit in VBA..
Vielen Dank
Ba
|