Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1548to1552
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Durchsuchen einer Datei und neue Werte holen

Durchsuchen einer Datei und neue Werte holen
21.03.2017 16:07:50
Björn
Hallo zusammen,
ich habe einen Code zusammengestupft um von einer Datei neue Werte in eine Arbeitsdatei zu holen.
Das funktioniert auch, wenn in der Quelldatei die erste Spalte das neue eineindeutige Kriterium ist.
Leider ist in der Quelldatei´, hier als Master.xlsm bezeichnet, das zu suchende Kriterium in der 3. Spalte.
Ich kenne mich im VBA Code nicht aus. Daher weiß ich nicht, welcher Code die Suche in einer speziellen Spalte ausführt.
Kann mir dazu jemand helfen?
Vielen herzlichen Dank.
Björn

hier der Code:
Sub Aktualisieren()
Dim wkb As Workbook
Dim wkb1 As Workbook
Dim wks As Worksheet
Dim wks1 As Worksheet
Dim rng As Range
Dim iRow As Integer
Dim i
Application.ScreenUpdating = False
On Error Resume Next
On Error GoTo 0
l = 1
For Each w In Workbooks
If w.Name = "Master.xlsm" Then
l = 0
Exit For
End If
Next w
If wkb Is Nothing And l = 1 Then
If Dir(ThisWorkbook.Path & "\Master.xlsm") = "" Then
Beep
MsgBox "Quelldatei wurde nicht gefunden!"
Exit Sub
Else
Workbooks.Open ThisWorkbook.Path & "\Master.xlsm"
End If
End If
Set wkb = ThisWorkbook
Set wkb1 = Workbooks("Master.xlsm")
wkb1.Activate
Set wks = wkb.Worksheets("Tabelle1")
Set wks1 = wkb1.Worksheets("Tabelle1")
anz = wks.Cells(65536, 1).End(xlUp).Row
anz1 = wks1.Cells(65536, 1).End(xlUp).Row
For z = 2 To anz1
suchwert = wks1.Cells(z, 1)
With wks.Range("a2:a" & anz)
Set c = .Find(suchwert, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
For s = 2 To 11
wks.Cells(c.Row, s) = wks1.Cells(z, s)
Next
Else
For s = 1 To 11
wks.Cells(anz + 1, s) = wks1.Cells(z, s)
Next
anz = wks.Cells(65536, 1).End(xlUp).Row
End If
End With
Next
Application.ScreenUpdating = True
End Sub

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Durchsuchen einer Datei und neue Werte holen
21.03.2017 18:44:36
Anton
Hallo Björn,
versuchs mal damit:
Sub Aktualisieren()
Dim wkb As Workbook
Dim wkb1 As Workbook
Dim wks As Worksheet
Dim wks1 As Worksheet
Dim rng As Range
Dim iRow As Integer
Dim i
Application.ScreenUpdating = False
On Error Resume Next
On Error GoTo 0
l = 1
For Each w In Workbooks
If w.Name = "Master.xlsm" Then
l = 0
Exit For
End If
Next w
If wkb Is Nothing And l = 1 Then
If Dir(ThisWorkbook.Path & "\Master.xlsm") = "" Then
Beep
MsgBox "Quelldatei wurde nicht gefunden!"
Exit Sub
Else
Workbooks.Open ThisWorkbook.Path & "\Master.xlsm"
End If
End If
Set wkb = ThisWorkbook
Set wkb1 = Workbooks("Master.xlsm")
wkb1.Activate
Set wks = wkb.Worksheets("Tabelle1")
Set wks1 = wkb1.Worksheets("Tabelle1")
anz = wks.Cells(65536, 3).End(xlUp).Row
anz1 = wks1.Cells(65536, 1).End(xlUp).Row
For z = 2 To anz1
suchwert = wks1.Cells(z, 1)
With wks.Range("c2:c" & anz)
Set c = .Find(suchwert, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
For s = 2 To 11
wks.Cells(c.Row, s) = wks1.Cells(z, s)
Next
Else
For s = 1 To 11
wks.Cells(anz + 1, s) = wks1.Cells(z, s)
Next
 anz = wks.Cells(65536, 3).End(xlUp).Row
End If
End With
Next
Application.ScreenUpdating = True
End Sub
VG Anton
Anzeige
AW: Durchsuchen einer Datei und neue Werte holen
22.03.2017 20:58:58
Björn
Hallo Anton,
danke für deine Hilfe. Das hat mich deutlich weiter gebracht.
Es hat nicht ganz geklappt, da du bei anz=wks.... die 3 eingetragen hast. Ich habe es in anz1=wks1.. eingetragen und dann hat es auch geklappt.
Kannst du mir noch kurz erläutern was es mit dem WKS1.Cells(65536, 3)... zu tun hat? Und wenn möglich auch noch das c2:c? :-)
Jetzt habe ich nochmal eine Frage:
Warum schreibt mir das VBA in meine Zieldatei auch erst ab der 3. Spalte? Das habe ich leider noch nicht herauslesen können, wo ich da drehen kann.
Anbei noch der Code, den ich getestet habe:
Sub Aktualisieren()
Dim wkb As Workbook
Dim wkb1 As Workbook
Dim wks As Worksheet
Dim wks1 As Worksheet
Dim rng As Range
Dim iRow As Integer
Dim i
Application.ScreenUpdating = False
On Error Resume Next
On Error GoTo 0
l = 1
For Each w In Workbooks
If w.Name = "Master.xlsm" Then
l = 0
Exit For
End If
Next w
If wkb Is Nothing And l = 1 Then
If Dir(ThisWorkbook.Path & "\Master.xlsm") = "" Then
Beep
MsgBox "Quelldatei wurde nicht gefunden!"
Exit Sub
Else
Workbooks.Open ThisWorkbook.Path & "\Master.xlsm"
End If
End If
Set wkb = ThisWorkbook
Set wkb1 = Workbooks("Master.xlsm")
wkb1.Activate
Set wks = wkb.Worksheets("Tabelle1")
Set wks1 = wkb1.Worksheets("Tabelle1")
anz = wks.Cells(65536, 1).End(xlUp).Row
anz1 = wks1.Cells(65536, 3).End(xlUp).Row
For z = 2 To anz1
suchwert = wks1.Cells(z, 1)
With wks.Range("c2:c" & anz)
Set c = .Find(suchwert, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
For s = 2 To 13
wks.Cells(c.Row, s) = wks1.Cells(z, s)
Next
Else
For s = 1 To 13
wks.Cells(anz + 1, s) = wks1.Cells(z, s)
Next
anz = wks.Cells(65536, 3).End(xlUp).Row
End If
End With
Next
Application.ScreenUpdating = True
End Sub

Anzeige

309 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige