habe mir folgendes Makro zusammengestellt:
Sub suche1()
Dim t As Worksheet, z As Range, SuchW As String, ersatz As String, erste As String
SuchW = InputBox("Suche")
ersatz = InputBox("Ersatz")
If SuchW = "" Then Exit Sub
For Each t In ActiveWorkbook.Worksheets
t.Activate
Set z = t.Cells.Find(SuchW)
If Not z Is Nothing Then
erste = z.Address
Do
z.Activate
z.Select
Selection.Replace What:=SuchW, Replacement:=ersatz, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Set z = Cells.FindNext(after:=ActiveCell)
Loop Until erste = z.Address
End If
Next t
End Sub
damit wollte ich suchen und ersetzen in allen Arbeitsblättern einer Arbeitsmappe. Für Blatt 1 funktioniert das auch einwandfrei, aber nach Beendigung des Ersetzens in Tabelle1, bekomme ich eine Fehlermeldung:
Objekt-oder With-Block-Variable nicht festgelegt.
Wo liegt mein Fehler? Wenn ich das ohne Ersetzen ausprobiere läuft das Makro einwandfrei durch. ich komme nicht drauf, warum Excel abbricht.
Vielen Dank für eure Hilfe
Gruß
Chris