ich habe ein Problem mit dem Filtern nach Monate.
Wenn in Spalte "A" ein Text steht, kommt immer ein Laufzeitfehler.
Wie kann ich dies verhindern?
Danke!
Gruß
Olga
https://www.herber.de/bbs/user/128938.xlsm
Option Explicit
Sub DatumSuchen()
Dim lngIndex As Long
Dim lngCount As Long
Dim Lol As Integer
ListBox1.Clear
ListBox1.ColumnCount = 2
lngCount = cboMonate.List(cboMonate.ListIndex, 1)
With ThisWorkbook.Worksheets("TB1")
For lngIndex = 2 To .UsedRange.Rows.Count
On Error GoTo weiter
If Month(.Cells(lngIndex, 1).Value) = lngCount Then
ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = .Cells(lngIndex, 1).Value
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(lngIndex, 2).Value
End If
weiter:
On Error GoTo 0
Next
End With
End Sub
Gruß WernerOption Explicit
Sub DatumSuchen()
Dim lngIndex As Long
Dim lngCount As Long
Dim Lol As Integer
ListBox1.Clear
ListBox1.ColumnCount = 2
lngCount = cboMonate.List(cboMonate.ListIndex, 1)
With ThisWorkbook.Worksheets("TB1")
For lngIndex = 2 To .UsedRange.Rows.Count
If IsDate(.Cells(lngIndex, 1)) Then
If Month(.Cells(lngIndex, 1).Value) = lngCount Then
ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = .Cells(lngIndex, 1).Value
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(lngIndex, 2).Value
End If
End If
Next
End With
End Sub
Gruß Werner