Potrebujem pomoc pri hľadaní spôsobu, ako kombinovať viac riadkov do jedného riadku v programe Excel.
Napríklad mám 8 stĺpcov (A - H) údajov vriadky 1 - 4 a 5 - 8 (tabuľka 1). Potrebujem metódu na presun všetkých stĺpcov riadkov 2 - 4 do stĺpcov I - AF riadku 1 a všetkých stĺpcov riadkov 4 - 8 do stĺpcov I - AF riadku 5 (tabuľka 2). Výsledné prázdne riadky nie sú ani potrebné. V skutočnosti musím túto metódu použiť niekoľkokrát. Nejaké nápady?
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
odpovede:
0 pre odpoveď č. 1Staral som sa o vytvorenie kódu VBA, neviemvašej úrovni v programe Excel .. Tiež som sa postaral o to, aby bol kód čo najjednoduchší. V tomto kóde (nižšie): Listy1 sú listy, kde sú údaje prezentované a prečítané. List2 je hárok, na ktorom sú údaje zapísané. RowsColsTransformer () je postup spustenia.
"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 to môže pomôcť.