Daten zusammenlegen ?
06.01.2005 21:54:48
mykey
ums kurz zu sagen:
ich hab ein makro mit dem zwei tabellen zusammengelegt werden.
in diesen sine einmal mehr einmal weniger einträge, und öfter mal doppelte namen+orte vorhanden.
folgendes soll dieses makro machen:
von den doppelten einträgen soll er eins in tabelle3 übernehmen und die restlichen doppelten löschen.
ich hab jetz auch irgendwie den faden verloren und weiss sehr wenig über VBA ...
schaut euch einfach mal den makro-text an. ich habe dort glaub ich einen fehler drin:
Sub Zusammenfassen()
Dim n As Variant
Dim i As Long
With Sheets("Tabelle1")
For i = 2 To .Cells(Rows.Count, 6).End(xlUp).Row
Name = .Cells(i, 6)
Set n = Sheets("Tabelle2").Columns(9).Find(What:=Name, LookIn:=xlValues, LookAt:=xlWhole)
lz = Sheets("Tabelle3").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Tabelle3").Cells(lz + 1, 1) = .Cells(i, 6)
Sheets("Tabelle3").Cells(lz + 1, 2) = .Cells(i, 9)
Sheets("Tabelle3").Cells(lz + 1, 4) = .Cells(i, 4)
If Not n Is Nothing Then
If .Cells(i, 9) = n(1, 8) Then Sheets("Tabelle3").Cells(lz + 1, 3) = n(1, 28)
End If
Next i
End With
With Sheets("Tabelle2")
For i = 2 To .Cells(Rows.Count, 9).End(xlUp).Row
Name = .Cells(i, 9)
Set n = Sheets("Tabelle1").Columns(6).Find(What:=Name, LookIn:=xlValues, LookAt:=xlWhole)
If n Is Nothing Then
lz = Sheets("Tabelle3").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Tabelle3").Cells(lz + 1, 1) = .Cells(i, 9)
Sheets("Tabelle3").Cells(lz + 1, 2) = .Cells(i, 16)
Sheets("Tabelle3").Cells(lz + 1, 3) = .Cells(i, 36)
End If
Next i
End With
With Sheets("Tabelle1")
For i = 2 To .Cells(Rows.Count, 9).End(xlUp).Row
Ort = .Cells(i, 9)
Set o = Sheets("Tabelle2").Columns(16).Find(What:=Ort, LookIn:=xlValues, LookAt:=xlWhole)
lz = Sheets("Tabelle3").Cells(Rows.Count, 1).End(xlUp).Row
If .Cells(i, 6) = "" Then
Sheets("Tabelle3").Cells(lz + 1, 2) = .Cells(i, 9)
Sheets("Tabelle3").Cells(lz + 1, 4) = .Cells(i, 4)
If Not o Is Nothing Then
If .Cells(i, 9) = o(1, 1) Then Sheets("Tabelle3").Cells(lz + 1, 3) = o(1, 21)
End If
End If
Next i
End With
With Sheets("Tabelle2")
For i = 2 To .Cells(Rows.Count, 16).End(xlUp).Row
Ort = .Cells(i, 16)
Set o = Sheets("Tabelle1").Columns(6).Find(What:=Ort, LookIn:=xlValues, LookAt:=xlWhole)
If o Is Nothing Then
If .Cells(i, 9) = "" Then
lz = Sheets("Tabelle3").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Tabelle3").Cells(lz + 1, 2) = .Cells(i, 16)
Sheets("Tabelle3").Cells(lz + 1, 3) = .Cells(i, 36)
End If
End If
Next i
End With
End Sub
die datei hab ich auch angehängt:
https://www.herber.de/bbs/user/15725.xls
kann mir einer sagen auf welchen internet-seiten erklärt wird wie ein makro aufgebaut ist ??? oder wenigstens die befehle erklärt werden ? die hilfe von ms excel finde ich zum sehr schlecht ...
mfG
mykey