AW: gelöst
14.05.2016 21:30:06
Piet
Hallo Constantin,
da war ich wohl etwas zu langsam, hatte bereits ein Makro entwickelt.
Hier der vollstaendigkeit halber meine Makro Lösung. Bin gerade fertig geworden.
mfg Piet
Option Explicit '14.5.2016 Piet für Herber Forum
Dim Tab1 As Object, lz1 As Long
Dim Tab2 As Object, lz2 As Long
Dim AC As Object, rFind As Object
Dim Adr1 As String, AdrN As String
Dim Schlüssel As String, Txt As String
Dim SuchName As String
'Zeichen suchen ; Schlüssel notieren
'Variante 1: mit Space bei Schlüssel
Sub Suche_Zeichen_in_Zeichenkette_1()
Set Tab1 = Worksheets("Tabelle1") 'Tabelle1
Set Tab2 = Worksheets("Tabelle2") 'Tabelle2
'letzte Zeile in Tabelle 1+2 finden
lz1 = Tab1.Range("A2").End(xlDown).Row
lz2 = Tab2.Range("A2").End(xlDown).Row
'alte Schlüssel Tabelle in B löschen
Tab1.Range("B2:B" & lz1).ClearContents
'Schleife für alle Typen in Tabelle2 Spalte "A"
For Each AC In Tab2.Range("A2:A" & lz2)
'Such-Name laden: (ohne oder mit Space)
SuchName = AC.Value 'Such-Name ohne Space
'Suchlauf nach AC Wert in Tabelle1 Spalte "A"
Set rFind = Tab1.Range("A1:A" & lz1).Find(What:=SuchName, After:=Tab2.Range("A1"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If Not rFind Is Nothing Then
Adr1 = rFind.Address '1. gefundene Adresse
AdrN = rFind.Address '1. next Adresse
Schlüssel = AC.Cells(1, 2) '"B" Schlüssel laden
'Text aus Spalte B laden (voriger Schlüssel)
Txt = rFind.Cells(1, 2).Value
If InStr(Txt, Schlüssel) = 0 Then
If Txt "" Then Txt = Txt & " / " 'mit Space
rFind.Cells(1, 2) = Txt & Schlüssel '1. Gefund. Schlüssel
End If
Do 'Do Loop für weitere Typen bis End Zeile
Set rFind = Tab1.Range("A2:A" & lz1).FindNext(After:=Tab2.Range(AdrN))
If rFind Is Nothing Then Exit Do Else AdrN = rFind.Address
'Text aus Spalte B laden (voriger Schlüssel)
Txt = rFind.Cells(1, 2).Value
If InStr(Txt, Schlüssel) = 0 Then
If Txt "" Then Txt = Txt & " / " 'mit Space
rFind.Cells(1, 2) = Txt & Schlüssel 'next Schlüssel
End If
Loop Until AdrN = Adr1
End If
Next AC
End S
ub