27.12.2025, 16:14
(Dieser Beitrag wurde zuletzt bearbeitet: 27.12.2025, 16:17 von Flotter Feger.)
Hallo,
Den Code in die Tabelle, aus der kopiert werden soll.
Sollte eigentlich auch in deinem 2007 klappen.
Beim Aufruf ... Tabelle2, "Datum", "Start", ... ist Tabelle2 nicht der Name des Sheets, sondern der CodeName ... der in Klammern im Projekt-Explorer steht.
Den Code in die Tabelle, aus der kopiert werden soll.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address(0, 0) = "A1" Then
Call Spalten_Automatisiert_umstellen(Tabelle2, "Datum", "Start", "Pause", "Ende", "Gesamt")
Cancel = True
End If
End Sub
Public Sub Spalten_Automatisiert_umstellen(ByVal wsTab As Worksheet, ParamArray Data() As Variant)
Dim lngI As Long
Dim aletzte As Long
Dim zletzte As Long
Dim spalte As Variant
Dim wsA As Worksheet
Set wsA = ActiveSheet
aletzte = wsA.Cells(Rows.Count, 1).End(xlUp).Row + 1
With wsTab
zletzte = .Cells(Rows.Count, 1).End(xlUp).Row + 1: If zletzte = 2 Then zletzte = 1
For lngI = LBound(Data) To UBound(Data)
spalte = SpaltenName(Data(lngI))
wsA.Range(wsA.Cells(1, spalte), wsA.Cells(aletzte, spalte)).Copy Destination:=.Cells(zletzte, lngI + 1)
Next lngI
If zletzte > 1 Then .Rows(zletzte).Delete shift:=xlShiftUp
End With
End Sub
Public Function SpaltenName(ByVal spalte As Variant) As Variant
Dim rng As Range
If IsNumeric(spalte) Then
SpaltenName = spalte
Else
Set rng = Range(Cells(1, 1), Cells(1, Columns.Count)).Find(What:=spalte, LookIn:=xlValues, LookAt:=xlWhole)
If Not rng Is Nothing Then
SpaltenName = Split(rng.Address(, 0), "$")(0)
End If
End If
End FunctionBeim Aufruf ... Tabelle2, "Datum", "Start", ... ist Tabelle2 nicht der Name des Sheets, sondern der CodeName ... der in Klammern im Projekt-Explorer steht.
_________
VG Sabina
VG Sabina

VBA copy und paste

