AW: Inhalte durchsuchen und Teil ersetzen
06.03.2010 11:39:35
fcs
Hallo Boris,
hier auch noch eine geschachtelte For-Next-Scheifen-Lösung und ein Lösung ähnlich der von Tino.
Grüß
Franz
Sub AATest()
'Sucht und ersetzt Groß-/Kleinschreibung genau
Dim wks1 As Worksheet, wks2 As Worksheet
Dim sText$, sSuch$, sErsatz$
Dim lZeile1&, lZeile2&
Set wks1 = Tabelle1
Set wks2 = Tabelle2
For lZeile1 = 1 To wks1.Cells(wks1.Rows.Count, 1).End(xlUp).Row
sText = wks1.Cells(lZeile1, 1).Text
For lZeile2 = 1 To wks2.Cells(wks2.Rows.Count, 3).End(xlUp).Row
sSuch = wks2.Cells(lZeile2, 3).Text
sErsatz = wks2.Cells(lZeile2, 3).Offset(0, 1).Text
If InStr(1, sText, sSuch) > 0 Then
sText = Replace(sText, sSuch, sErsatz)
End If
Next
wks1.Cells(lZeile1, 1).Value = sText
Next
End Sub
Sub BBTest()
'wie Suchen/Ersetzen im Menü
Dim wks1 As Worksheet, wks2 As Worksheet
Dim sSuch$, sErsatz$
Dim lZeile1&, lZeile2&, Bereich As Range
Set wks1 = Tabelle1
Set wks2 = Tabelle2
With wks1
Set Bereich = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
With wks2
For lZeile2 = 1 To .Cells(.Rows.Count, 3).End(xlUp).Row
sSuch = .Cells(lZeile2, 3).Text
sErsatz = .Cells(lZeile2, 3).Offset(0, 1).Text
Bereich.Replace What:=sSuch, replacement:=sErsatz, lookat:=xlPart, _
MatchCase:=False, matchbyte:=True
Next
End With
End Sub