AW: Zeillenummern ersten und letzten Wertes ermitteln
20.03.2014 13:12:21
fcs
Hallo Valeri,
könnte man so per Makro lösen.
Gruß
Franz
'Code in einem allgemeinen Modul - Makro zugewiesen zu einer Form oder einem _
Formular-Steuerelement inmm tabellenblatt
Sub cmbCheck_U_G_Tage()
Dim rng As Range, ZelleU1 As Range, ZelleU2 As Range, ZelleG1 As Range, ZelleG2 As Range
Dim Zeile As Long
Dim intAnz_U As Integer, intAnz_G As Integer
Dim msgText As String
'Ermitteln der 1. / letzten Zelle mit "U" bzw. "G" in 1. Spalte der selektierten Zellen.
Set rng = Selection
intAnz_U = 0: intAnz_G = 0
For Zeile = 1 To rng.Rows.Count
If rng.Cells(Zeile, 1).Value = "U" Then
intAnz_U = intAnz_U + 1
If ZelleU1 Is Nothing Then
Set ZelleU1 = rng.Cells(Zeile, 1)
Set ZelleU2 = rng.Cells(Zeile, 1)
Else
Set ZelleU2 = rng.Cells(Zeile, 1)
End If
ElseIf rng.Cells(Zeile, 1).Value = "G" Then
intAnz_G = intAnz_G + 1
If ZelleG1 Is Nothing Then
Set ZelleG1 = rng.Cells(Zeile, 1)
Set ZelleG2 = rng.Cells(Zeile, 1)
Else
Set ZelleG2 = rng.Cells(Zeile, 1)
End If
End If
Next Zeile
'Ergebnisausgabe
msgText = "Gleit- und Urlaubstage in Bereich " & rng.Columns(1).Address(False, False)
If intAnz_U = 0 Then
msgText = msgText & vbLf & "Keine U-Tage"
Else
msgText = msgText & vbLf & intAnz_U & " U-Tag" & IIf(intAnz_U = 1, "", "e") _
& " von " & ZelleU1.Address(False, False) _
& " bis " & ZelleU2.Address(False, False)
End If
If intAnz_G = 0 Then
msgText = msgText & vbLf & "Keine G-Tage"
Else
msgText = msgText & vbLf & intAnz_G & " G-Tag" & IIf(intAnz_G = 1, "", "e") _
& " von " & ZelleG1.Address(False, False) _
& " bis " & ZelleG2.Address(False, False)
End If
MsgBox msgText, vbInformation + vbOKOnly, "Anzeige Ulaubs- und Gleittage in Woche"
End Sub