Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1840to1844
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

Spalten kopieren

Spalten kopieren
12.08.2021 10:54:32
Patricia
Hallo zusammen
Ich bin sicher, es gibt eine einfachere Variante als meine - hat jemand eine Idee?
Grüsse
Patricia
With tbl_original
letzteSpalte = .Cells(1, 256).End(xlToLeft).Column
letzteZeile = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To letzteSpalte
If .Range("a" & i).Value = "Purch. organization" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
If .Range("a" & i).Value = "Supplier/Supplyinb Plant" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
If .Range("a" & i).Value = "Currency" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
If .Range("a" & i).Value = "Accrual estimate" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
If .Range("a" & i).Value = "G/L Account" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
If .Range("a" & i).Value = "Cost Center" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
If .Range("a" & i).Value = "Order" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
Next i
End With

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Spalten kopieren
12.08.2021 11:14:24
Peter
Hallo Patricia,
hast du dich da verschrieben? Du machst eine Schleife über die Spalten auf aber suchst '.Range("a" & i)'? Das sind doch die ZEILEN immer in Spalte 'A'!?
In der Annahme, die wolltest die oberste Zelle jeder SPALTE abfragen versuche dies:

With tbl_original
letzteSpalte = .Cells(1, Columns.Count).End(xlToLeft).Column
letzteZeile = .Cells(Rows.Count, 1).End(xlUp).Row
For ii = 1 To letzteSpalte 'Ich nehme für Hilfsvariablen immer Doppelbuchstaben, dann kann man sie im Code auch suchen...
Select Case .Cells(1, ii)
Case "Purch. organization", "Supplier/Supplyinb Plant", "Currency", "Accrual estimate", _
"G/L Account", "Cost Center", "Order"
.Cells(1, ii).EntireColumn.Copy Destination:=tbl_copy.Cells(1, ii)
End Select
Next ii
End With

Anzeige
AW: Spalten kopieren
12.08.2021 11:15:50
Rudi
Hallo,

With tbl_original
letzteSpalte = .Cells(1, 256).End(xlToLeft).Column
letzteZeile = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To letzteSpalte
Select Case .Range("A" & i)
Case "Purch. organization", "Supplier/Supplyinb Plant", _
"Currency", "Accrual estimate", "G/L Account", "Cost Center", "Order"
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End Select
Next i
End With
Gruß
Rudi
AW: Spalten kopieren
12.08.2021 11:20:36
Daniel
Hi
Statt den vielen IFs:

Select Case Range("a" & i).Value
Case "Purch. organization", "Supplier/Supplyinb Plant",  "Currency", ...
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
Case else
Ende Select
Bei den ... musst du natürlich die Liste mit den Begriffen weiterführen.
Gruß Daniel
Anzeige
AW: Spalten kopieren
12.08.2021 11:27:33
Patricia
ah der erste Versuch war ja schon mal falsch.
Habe es so angepasst, aber jetzt kopiert er nur die erste Kolonne ("Purch. organization", die anderen nicht, auch wenn die vorhanden sind..
An was könnte das liegen?
Vielen Dank
Patricia
With tbl_original
letzteSpalte = .Cells(1, 256).End(xlToLeft).Column
letzteZeile = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To letzteSpalte
If .Cells(1, i).Value = "Purch. organization" Or _
Cells(1, i).Value = "Supplier/Supplying Plant" Or _
Cells(1, i).Value = "Currency" Or _
Cells(1, i).Value = "Accrual estimate" Or _
Cells(1, i).Value = "GL/ Account" Or _
Cells(1, i).Value = "Order" Then
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End If
Next i
Anzeige
AW: Spalten kopieren
12.08.2021 12:00:16
Rudi

With tbl_original
letzteSpalte = .Cells(1, 256).End(xlToLeft).Column
letzteZeile = .Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To letzteSpalte
Select Case .Cells(1, i)
Case "Purch. organization", "Supplier/Supplyinb Plant", _
"Currency", "Accrual estimate", "G/L Account", "Cost Center", "Order"
.Cells(1, i).EntireColumn.Copy Destination:=tbl_copy.Cells(1, i)
End Select
Next i
End With

AW: Spalten kopieren
12.08.2021 13:02:44
GerdL
Moin,
probier mal mit:
letzteSpalte = .Cells(1, 1).End(xlToRight).Column
Gruß Gerd

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige