/ / Mehrere Zeilen in einer Zeile kombinieren - Excel - Excel, Excel-VBA, VBA

Kombinieren Sie mehrere Zeilen zu einer Zeile - Excel - Excel, Excel-VBA, VBA

Ich brauche Hilfe bei der Suche nach einer Möglichkeit, mehrere Zeilen zu einer Zeile in Excel zu kombinieren.

Zum Beispiel habe ich 8 Spalten (A - H) von Daten inReihen 1 - 4 und 5 - 8 (Tabelle 1). Ich brauche eine Methode, um alle Spalten der Zeilen 2 - 4 in die Spalten I - AF der Zeile 1 und alle Spalten der Zeilen 4 - 8 in die Spalten I - AF der Zeile 5 (Tabelle 2) zu verschieben. Die resultierenden leeren Zeilen sind auch nicht notwendig. In Wirklichkeit muss ich diese Methode mehrmals anwenden. Irgendwelche Ideen?

Table 1
A   B   C   D   E   F   G   H
1   1   2   3   4   5   6   7   8
2   9   10  11  12  13  14  15  16
3   17  18  19  20  21  22  23  24
4   25  26  27  28  29  30  31  32
5   1   2   3   4   5   6   7   8
6   9   10  11  12  13  14  15  16
7   17  18  19  20  21  22  23  24
8   25  26  27  28  29  30  31  32

Table 2
A   B   C   D   E   F   G   H   I   …   AD  AE  AF
1   1   2   3   4   5   6   7   8   9   …   30  31  32
2
3
4
5   1   2   3   4   5   6   7   8   9   …   30  31  32
6
7
8

Antworten:

0 für die Antwort № 1

Ich habe darauf geachtet, einen VBA-Code zu entwickeln, ich weiß es nichtIhr Niveau in Excel. Ich habe auch darauf geachtet, den Code so einfach wie möglich zu machen. In diesem Code (unten): Sheets1 ist das Blatt, in dem die Daten dargestellt und gelesen werden. Sheet2 ist das Blatt, in das die Daten geschrieben werden. RowsColsTransformer () ist die auszuführende Prozedur.

"VBA:

Sub RowsColsTransformer()
Dim CurrentLine As Integer
Dim CurrentLine2 As Integer
Dim CurrentCols2 As Integer
Dim Max As Integer

CurrentLine2 = 2
CurrentCols2 = 1
Max = 10 " -- Number of lines in the sheet where data will be read.
For CurrentLine = 2 To Max
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 1)
CurrentCols2 = CurrentCols2 + 1
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 2)
CurrentCols2 = CurrentCols2 + 1
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 3)
CurrentCols2 = CurrentCols2 + 1
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 4)
CurrentCols2 = CurrentCols2 + 1
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 5)
CurrentCols2 = CurrentCols2 + 1
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 6)
CurrentCols2 = CurrentCols2 + 1
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 7)
CurrentCols2 = CurrentCols2 + 1
Sheets(2).Cells(CurrentLine2, CurrentCols2) = Sheets(1).Cells(CurrentLine, 8)
CurrentCols2 = CurrentCols2 + 1
"-- Reintialize Line and Column
If CurrentLine Mod 4 = 1 And CurrentLine > 1 Then
CurrentLine2 = CurrentLine2 + 1
CurrentCols2 = 1
End If
Next CurrentLine
End Sub

Holp das kann helfen.