Code:
Sub Ref_finden()
Dim rFound As Range
Dim rSearch As Range
Dim sFirstAddress As String
'Set search range to column B
Range("B1").Select
Set rSearch = Intersect(ActiveSheet.UsedRange, ActiveSheet.Columns(2))
'Find the first occurance of "NEU"
Set rFound = rSearch.Find(what:="NEU", _
after:=rSearch.Cells(rSearch.Cells.Count), _
lookat:=xlWhole)
'If "NEU" was found
If Not rFound Is Nothing Then
'Store the address in a variable
sFirstAddress = rFound.Address
sLastAddress = Cells(Rows.Count, 2).End(xlUp).Row
'Start a loop
i = 1
a = 8
m = 57
Do
Worksheets("Tabelle2").Activate
Set myRange = Worksheets("Tabelle2").Cells(i, a)
Worksheets("Tabelle1").Activate
rFound.Cells.Select
Selection.Replace what:="NEU", replacement:="700BGI08000" & m
Selection.Copy
Worksheets("Tabelle2").Activate
myRange.Select
ActiveSheet.Paste
Application.CutCopyMode = False
'Set rFound = rSearch.FindNext(rFound)
Set rFound = rSearch.FindNext(rFound)
i = i + 1
m = m + 1
'Stop when Find loops back to the first cell found
Loop Until rFound.Address = sFirstAddress
End If
End Sub
--
Wolfgang
--
Wolfgang
> Kann mir jemand den Code so verändern, dass alles einwandfrei und ohne
> Fehlerhinweis läuft.
Ich versuche mich mal :-)
> 'Set rFound = rSearch.FindNext(rFound)
> Set rFound = rSearch.FindNext(rFound)
> i = i + 1
> m = m + 1
> 'Stop when Find loops back to the first cell found
> Loop Until rFound.Address = sFirstAddress
> End If
> End Sub
Problem ist, das Du immer wieder neu suchst, und am Ende die Suche
verständlicherweise kein Ergebnis mehr liefert - alle Werte wurden ja
bereits ersetzt.
Daher das Do-Loop wie folgt verlassen:
Loop Until rFound Is Nothing
HTH
Michi
Vielen Dank Michael und ein schönes Wochenede
--
Wolfgang