Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
VBA copy und paste
#4
Hallo,

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 Function
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.
_________
VG Sabina
Zitieren


Nachrichten in diesem Thema
VBA copy und paste - von Thomasius - 23.12.2025, 19:15
RE: VBA copy und paste - von Flotter Feger - 23.12.2025, 23:04
RE: VBA copy und paste - von Thomasius - 24.12.2025, 13:04
RE: VBA copy und paste - von Flotter Feger - 27.12.2025, 16:14
RE: VBA copy und paste - von Thomasius - 29.12.2025, 18:44
RE: VBA copy und paste - von Flotter Feger - 30.12.2025, 13:20
RE: VBA copy und paste - von Thomasius - 30.12.2025, 19:44
RE: VBA copy und paste - von Flotter Feger - 03.01.2026, 18:33
RE: VBA copy und paste - von Thomasius - 03.01.2026, 20:39
RE: VBA copy und paste - von Flotter Feger - 04.01.2026, 00:51
RE: VBA copy und paste - von PetrolMaxxe - 04.01.2026, 10:53
RE: VBA copy und paste - von RPP63 - 04.01.2026, 11:20
RE: VBA copy und paste - von PetrolMaxxe - 04.01.2026, 11:24
RE: VBA copy und paste - von PetrolMaxxe - 04.01.2026, 11:59
RE: VBA copy und paste - von Flotter Feger - 05.01.2026, 07:41
RE: VBA copy und paste - von PetrolMaxxe - 05.01.2026, 12:31
RE: VBA copy und paste - von Thomasius - 05.01.2026, 16:12

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 2 Gast/Gäste




Hinweis auf Angebot Excel-Inside - lang    Keine Lösung gefunden? Du kannst Dich gerne an unser erfahrenes Experten-Team wenden um dein Anliegen zu besprechen.
   Gerne erstellen wir auf dieser Basis ein Angebot.
   Sende deine Anfrage einfach
per E-Mail an anfrage@excel-inside.de


Powerd and supported by Excel-InsideSolutions