|
versuchs mal damit. kopiere den Code in eine neue leere Userform und starte sie. Wichtig ist das in der Datumszeile auch wirklich ein Datum drin steht und kein Text. Die Labels werden erst erstellt wenn auch ein Name gefunden wird.
Private Sub UserForm_Initialize()
Dim mitarbeiterStatus As String
Dim i As Long, toppos
Dim rng As Range, rngMA As Range
Set rng = Worksheets("2025").Range("AW2:OX2").Find(Date, LookIn:=xlValues, lookat:=xlWhole)
If rng Is Nothing Then
MsgBox "Keine Daten für das aktuelle Datum gefunden."
Exit Sub
End If
i = 1
For Each rngMA In Worksheets("2025").Range("D7:D32")
if rngMA.value<>"" then
mitarbeiterStatus = Worksheets("2025").Cells(rngMA.Row, rng.Column)
With Me.Controls.Add("Forms.Label.1", "lblMA" & i)
.Caption = rngMA
If toppos = 0 Then toppos = 5
.Top = IIf(toppos = 0, 5, toppos)
.Left = 5
End With
With Me.Controls.Add("Forms.Label.1", "lblStatus" & i)
.Caption = mitarbeiterStatus
.Top = toppos
toppos = .Top + .Height + 5
.Left = Me.Controls("lblMA" & i).Width + 5 + 5
'Farbcode für Status
Select Case mitarbeiterStatus
Case "K"
.BackColor = vbRed
Case "O"
.BackColor = vbWhite
Case "M"
.BackColor = vbMagenta
Case "1"
.BackColor = vbGreen
End Select
End With
end if
Next
End Sub
|