ich komme nicht weiter....
ich brauche ein Makro, dass von Tabellenblatt 2 die Daten aus
B2 bis Ende kopiert und in Tabellenblatt 1 in die nächste freie ZELLE in Spalte A einfügt.
Ist das möglich?
Danke schon mal für eure Hilfe :)
Sub a()
Dim Wb As Workbook
Dim WsQ As Worksheet
Dim WsZ As Worksheet
Set Wb = ThisWorkbook
With Wb
Set WsQ = .Worksheets(2)
Set WsZ = .Worksheets(1)
End With
With WsQ
.Range("B2:B" & .Cells(.Rows.Count, 2).End(xlUp).Row).Copy _
Destination:=WsZ.Range("A" & WsZ.Cells(WsZ.Rows.Count, 1).End(xlUp).Row + 1)
End With
End Sub
LG
Sub a()
Dim Wb As Workbook
Dim WsQ As Worksheet
Dim WsZ As Worksheet
Set Wb = ThisWorkbook
With Wb
'Das Quell-Blatt bestimmen...
Set WsQ = .Worksheets(2) '...in dem Fall das 2. Blatt der Mappe (von links)
'Alternativ, ein Blatt mit bestimmtem Namen als Quell-Blatt bestimmen
'Set WsQ = .Worksheets("ABC") 'Blatt mit dem Namen "ABC"
'Das Ziel-Blatt bestimmen...
Set WsZ = .Worksheets(1) '...in dem Fall das 1. Blatt der Mappe (von links)
'Alternativ, ein Blatt mit bestimmtem Namen als Quell-Blatt bestimmen
'Set WsZ = .Worksheets("Lorem") 'Blatt mit dem Namen "Lorem"
End With
'Im Quell-Blatt...
With WsQ
'...einen Bereich kopieren...
'.cells(.rows.count, 2).end(xlup).row sucht die letzte gefüllte Zelle in Spalt B,
'das ist Spalte 2 (von links)
.Range("B2:B" & .Cells(.Rows.Count, 2).End(xlUp).Row).Copy _
Destination:=WsZ.Range("A" & WsZ.Cells(WsZ.Rows.Count, 1).End(xlUp).Row + 1)
'>>> genauso sucht WsZ.Cells(WsZ.Rows.Count, 1).end(xlup).Row die letzte gefüllte Zelle
'in Spalte A, das ist Spalte 1 --> soll also hier das Spalten-Ende von zB Spalte G _
heran-
'gezogen werden, müsste es WsZ.Cells(WsZ.Rows.Count, 7).End(xlup).Row lauten
'+1 ist erforderlich weil die Daten ja nicht in die letzte befüllte Zelle sondern in _
die
'nächste Zelle, die bereits LEER ist, geschrieben werden sollen...
'Zum Teste...
Application.ReferenceStyle = xlR1C1 'Zeigt statt Spalten-Buchstaben Ziffern an
Application.ReferenceStyle = xlA1 'Zeigt statt Spalten-Ziffern Buchstaben an
End With
End Sub
LG
Sub a()
Dim Wb As Workbook
Dim WsQ As Worksheet
Dim WsZ As Worksheet
Set Wb = ThisWorkbook
'ggf. anpassen...
With Wb
Set WsQ = .Worksheets(2) '...VON Tabellenblatt 2
Set WsZ = .Worksheets(1) '...NACH Tabellenblatt 1
End With
With WsQ
'B2:Bx in die nächste freie Zelle A kopieren
.Range("B2:B" & .Cells(.Rows.Count, 2).End(xlUp).Row).Copy _
Destination:=WsZ.Range("A" & WsZ.Cells(WsZ.Rows.Count, 1).End(xlUp).Row + 1)
'F2:Fx in die nächste freie Zelle B kopieren
.Range("F2:F" & .Cells(.Rows.Count, 6).End(xlUp).Row).Copy _
Destination:=WsZ.Range("B" & WsZ.Cells(WsZ.Rows.Count, 2).End(xlUp).Row + 1)
'H2:Hx in die nächste freie Zelle C kopieren
.Range("H2:H" & .Cells(.Rows.Count, 8).End(xlUp).Row).Copy _
Destination:=WsZ.Range("C" & WsZ.Cells(WsZ.Rows.Count, 3).End(xlUp).Row + 1)
'AB2:ABx in die nächste freie Zelle D kopieren
.Range("AB2:AB" & .Cells(.Rows.Count, 28).End(xlUp).Row).Copy _
Destination:=WsZ.Range("D" & WsZ.Cells(WsZ.Rows.Count, 4).End(xlUp).Row + 1)
'AJ2:AJx in die nächste freie Zelle E kopieren
.Range("AJ2:AJ" & .Cells(.Rows.Count, 36).End(xlUp).Row).Copy _
Destination:=WsZ.Range("E" & WsZ.Cells(WsZ.Rows.Count, 5).End(xlUp).Row + 1)
'CA2:CAx in die nächste freie Zelle F kopieren
.Range("CA2:CA" & .Cells(.Rows.Count, 79).End(xlUp).Row).Copy _
Destination:=WsZ.Range("F" & WsZ.Cells(WsZ.Rows.Count, 6).End(xlUp).Row + 1)
End With
End Sub
Wenn Du die Quell- und Ziel-Tabellenblätter lieber mit Namen ansprechen möchtest, also nicht mit ihrer Position in der Mappe (aktuell vom Blatt 2 ins Blatt 1 kopieren), müsstest Du diesen Teil 'ggf. anpassen...
With Wb
Set WsQ = .Worksheets(2) '...VON Tabellenblatt 2
Set WsZ = .Worksheets(1) '...NACH Tabellenblatt 1
End With
mit diesem ersetzen With Wb
Set WsQ = .Worksheets("DeinQuellblattName")
Set WsZ = .Worksheets("DeinZielblattName")
End With
LG
Sub copy()
Dim Wb As Workbook
Dim WsQ As Worksheet
Dim WsZ As Worksheet
Set Wb = ThisWorkbook
'ggf. anpassen...
With Wb
Set WsQ = .Worksheets("Abrechnung einfügen")
Set WsZ = .Worksheets("Abrechnung")
End With
With WsQ
'B2:Bx in die nächste freie Zelle A kopieren
.Range("B2:B" & .Cells(.Rows.Count, 2).End(xlUp).Row).copy _
Destination:=WsZ.Range("A" & WsZ.Cells(WsZ.Rows.Count, 1).End(xlUp).Row + 1)
'F2:Fx in die nächste freie Zelle B kopieren
.Range("M2:M" & .Cells(.Rows.Count, 13).End(xlUp).Row).copy _
Destination:=WsZ.Range("I" & WsZ.Cells(WsZ.Rows.Count, 9).End(xlUp).Row + 1)
'H2:Hx in die nächste freie Zelle C kopieren
.Range("AB2:AB" & .Cells(.Rows.Count, 28).End(xlUp).Row).copy _
Destination:=WsZ.Range("D" & WsZ.Cells(WsZ.Rows.Count, 4).End(xlUp).Row + 1)
'AB2:ABx in die nächste freie Zelle D kopieren
.Range("AY2:AY" & .Cells(.Rows.Count, 51).End(xlUp).Row).copy _
Destination:=WsZ.Range("E" & WsZ.Cells(WsZ.Rows.Count, 5).End(xlUp).Row + 1)
'AJ2:AJx in die nächste freie Zelle E kopieren
.Range("bl2:bl" & .Cells(.Rows.Count, 64).End(xlUp).Row).copy _
Destination:=WsZ.Range("F" & WsZ.Cells(WsZ.Rows.Count, 6).End(xlUp).Row + 1)
'AJ2:AJx in die nächste freie Zelle E kopieren
.Range("bn2:bn" & .Cells(.Rows.Count, 66).End(xlUp).Row).copy _
Destination:=WsZ.Range("G" & WsZ.Cells(WsZ.Rows.Count, 7).End(xlUp).Row + 1)
'CA2:CAx in die nächste freie Zelle F kopieren
.Range("CA2:CA" & .Cells(.Rows.Count, 79).End(xlUp).Row).copy _
Destination:=WsZ.Range("H" & WsZ.Cells(WsZ.Rows.Count, 8).End(xlUp).Row + 1)
End With
End Sub
$A$4
$I$1156
$D$1156
$E$1187
$F$1218
$G$1218
$H$1249