Hilfe bei Filterschleife
14.11.2005 22:43:47
Peter
ich habe mir eine Schleife gebastelt um mittels des Filters best. Begriffe
zu zählen und zu erfassen.
Leider funktioniert die Sache mit dem Zählen nicht so richtig.
Wer kann helfen?
Danke Peter
Option Explicit
Sub FilternZählen()
Dim AnzahlSTO As Integer
Dim IntJahr As Integer
Dim NrAbt As Integer
Dim intMonth As Integer
Dim x As Integer
Dim MonatsAnf As Date
Dim MonatsEnd As Date
Dim i As Long
Dim z As Long
x = 1
z = Range("A1").CurrentRegion.Rows.Count
IntJahr = Year(Date)
For intMonth = 1 To 2
For NrAbt = 1 To 9
For i = 2 To z
MonatsAnf = CDate(DateSerial(IntJahr, intMonth, 1))
MonatsEnd = CDate(DateSerial(IntJahr, intMonth + 1, 0))
With Range("A1")
.AutoFilter Field:=3, Criteria1:=">=" & CDbl(MonatsAnf), Operator:=xlAnd, _
Criteria2:="<=" & CDbl(MonatsEnd)
.AutoFilter Field:=2, Criteria1:="Abt" & NrAbt
.AutoFilter Field:=5, Criteria1:="STO"
End With
If Rows(i).Hidden = False Then AnzahlSTO = AnzahlSTO + 1
Worksheets("Tabelle2").Cells(NrAbt + 1, intMonth + 1) = AnzahlSTO
Next i
MsgBox "Monat: " & intMonth & Chr(13) & _
"Abteilung: " & NrAbt & Chr(13) & _
"Anzahl im Monat: " & AnzahlSTO
ActiveSheet.AutoFilterMode = False
Next NrAbt
Next intMonth
End Sub