AW: So z.B.
18.10.2017 10:24:51
Peter(silie)
Hallo,
dann könntest du folgenden Code probieren der mit .Find und .FindNext arbeitet.
Worksheet, Workbook und Range Variablen musst du auf dich anpassen!
Option Explicit
Sub Transfer_Data()
Dim ws_Daten As Worksheet
Dim rowsToCopy As Variant
Dim rng, tmp As Range
Dim lRow As Long
Set ws_Daten = ThisWorkbook.Sheets(1)
With ws_Daten
lRow = .Cells(.Rows.Count, 4).End(xlUp).Row
Set rng = .Range(.Cells(1, 4), .Cells(lRow, 4))
rowsToCopy = Get_Row_Array(rng, "T_TL xxx oooo")
If IsArray(rowsToCopy) Then
Transfer_data_To_other_Workbook rowsToCopy, ws_Daten
End If
End With
End Sub
Private Function Get_Row_Array(ByVal rng As Range, ByVal ValueToFind As Variant) As Variant
Dim array_() As Variant
Dim counter As Long
Dim firstAddress
Dim c As Range
With rng
Set c = .Find(ValueToFind, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
counter = 0
Do
ReDim Preserve array_(counter)
array_(counter) = c.Row
counter = counter + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address firstAddress
End If
End With
Get_Row_Array = array_
End Function
Private Function Transfer_data_To_other_Workbook(ByVal array_ As Variant, ByVal FromWorksheet) _
As Boolean
Dim varItem As Variant
Dim ws As Worksheet
Dim wb As Workbook
Dim lRow As Long
Dim tmp As Range
Set wb = Workbooks.Open("Dein WB Pfad")
Set ws = wb.Sheets("Worksheet wo es rein soll")
With ws
lRow = .Cells(.Rows.Count, 1).End(xlUp) + 1
For Each varItem In array_
With FromWorksheet
Set tmp = .Range(.Cells(varItem, 2), .Cells(varItem, 4))
End With
.Range("A" & lRow).Resize(, tmp.Columns.Count) = tmp.Value
Set tmp = Nothing
lRow = lRow + 1
Next varItem
End With
End Function