Find-Schleife
22.05.2008 19:59:05
Christian
ich werd noch verrückt!
kann mir bitte jemand sagen, warum dieses makro nicht funktioniert:
Sub t()
Dim lngletzte As Long, i As Long, strSuchbegriff As String
Dim rSuche As Range, rFinde As Range, strErste As Range, lngReihe As Long
lngletzte = IIf(IsEmpty(Cells(Rows.Count, 4)), Cells(Rows.Count, 4).End(xlUp).Row, Rows.Count)
Set rFinde = Range("A1:A65536")
For i = 1 To lngletzte
strSuchbegriff = Cells(i, 4).Value
Set rSuche = rFinde.Find(What:=strSuchbegriff, LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext)
If Not rSuche Is Nothing Then
strErste = rSuche.Address
Do
lngReihe = rSuche.Row
Range(Cells(lngReihe, 1), Cells(lngReihe, 3)).Copy Sheets(2).Range("A65536").End(xlUp). _
_
_
Offset(1, 0)
Set rSuche = rFinde.FindNext(rSuche)
Loop While Not rSuche Is Nothing And strErste rSuche.Address
End If
Next i
Set rFinde = Nothing
Set rSuche = Nothing
End Sub
Ich bekomme jedesmal Fehler91 (Withblockvariable).
Wenn ich die Do-Schleife rausnehme (Makro t) geht es, aber ich seh den Fehler nicht .
Hier noch ne kleine Beispieldatei:
https://www.herber.de/bbs/user/52560.xls
Gruß
Christian