|  
                                             
	Hallo nochmal! 
	  
	dank deinem code und der seite RegExr konnte ich meine gewünschten zeilen alle finden :) 
Option Explicit
'YES kopiert alle PPD id's in Tabelle2
Public Sub suchen_und_kopieren()
    Dim strSQL As String
    strSQL = get_sql_string
 
    Dim regEx As New RegExp
    With regEx
        .Global = True
        .IgnoreCase = False
        .MultiLine = True
        .Pattern = "PPD(?!_)[A-Z;a-z;0-9]+"            
    End With
     
    Dim colMatches As MatchCollection
    Dim m As Match
     
    Set colMatches = regEx.Execute(strSQL)
 
    If colMatches.Count = 0 Then
        GoTo clean_up
    End If
 
    For Each m In colMatches
        With Worksheets("Tabelle2")
            .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row + 1, 1) = Right(m.Value, 10)
        End With
Next m
clean_up:
    If Not colMatches Is Nothing Then Set colMatches = Nothing
    If Not regEx Is Nothing Then Set regEx = Nothing
    
    
End Sub
 
Private Function get_sql_string() As String
    Dim l As Long, k As Long
    Dim s As String
     
    With Worksheets("Tabelle1")
        k = .Cells(.Rows.Count, 1).End(xlUp).Row
        For l = 1 To k
            s = s & .Cells(l, 1)
        Next l
    End With
     
    get_sql_string = s
End Function
	und mit diesem code habe ich geschafft die richtigen froms zu kopieren : 
Option Explicit
'YES kopiert alle FROM in Tabelle2
Public Sub suchen_und_kopieren()
    Dim strSQL As String
    strSQL = get_sql_string
 
    Dim regEx As New RegExp
    With regEx
        .Global = True
        .IgnoreCase = False
        .MultiLine = True
        .Pattern = "FROM\s+(?!POSITION)(?!AND)\D[_-z;.-9;A-Z]+"                
    End With
     
    Dim colMatches As MatchCollection
    Dim m As Match
     
    Set colMatches = regEx.Execute(strSQL)
 
    If colMatches.Count = 0 Then
        GoTo clean_up
    End If
 
    For Each m In colMatches
        With Worksheets("Tabelle2")
            .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row + 1, 1) = Left(m.Value, 50)
        End With
Next m
clean_up:
    If Not colMatches Is Nothing Then Set colMatches = Nothing
    If Not regEx Is Nothing Then Set regEx = Nothing
    
    
End Sub
 
Private Function get_sql_string() As String
    Dim l As Long, k As Long
    Dim s As String
     
    With Worksheets("Tabelle1")
        k = .Cells(.Rows.Count, 1).End(xlUp).Row
        For l = 1 To k
            s = s & .Cells(l, 1)
        Next l
    End With
     
    get_sql_string = s
End Function
Wie schaffe ich es nun, die beiden codes so zusammen zu führen, dass das ergebnis ca folgender maßen aussieht:
ppd123456
from blablabla
from blabla
ppd32424
from xyzxyz
from abcabc
also es soll im query schritt für schritt suchen, sobald eine ppd gefunden wird kopieren und sobald ein from gefunden wird diese kopieren und nicht erst alle ppds und danach alle froms :)
Ich hoffe ich konnte mich halbwegs gut ausdrücken; vielen dank im vorraus :)
	  
     |