我有想要轉置的數據,這應該很容易。但是,我需要分組轉置多行。每組中的最後一行都有特定的文本,所以我不知道是否有某種方法可以創建搜尋文本與範圍的範圍? (這行得通嗎?=if(isnumber(search(“TEXT”,A1))
。我嘗試創建一個宏,但顯然我需要代碼將數據轉置到電子表格中,而不是一遍又一遍地轉置相同的數據。任何幫助都會很棒!
這是我需要的視覺效果(因為我無法格式化它,它看起來很有趣,而且因為我是新手,所以我無法嵌入它,所以我包含了行/列的外觀/應該的視覺效果的鏈接看起來像:
由此:
Column A
Row A1
Row A2
Row A3
Row A4
Row A5
Row A6
Row A7
Row A8
Row A9
Row A10
Row A11
Row A12
Row A13
對此:
Col A Col B Col C Col D Col E
Row A1 Row A2 Row A3 Row A4
Row A5 Row A6 Row A7 Row A8 Row A9
Row A10 Row A11 Row A12 Row A13
這是我找到的循環程式碼:
Sub Test1()
'UpdatebyExtendoffice20161222
Dim x As Integer
Application.ScreenUpdating = False
' Set numrows = number of rows of data.
NumRows = Range("A1", Range("A8”).End(xlDown)).Rows.Count
' Select cell a1.
Range("A1").Select
' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
' Insert your code here.
' Selects cell down 7 row from active cell.
ActiveCell.Offset(7, 0).Select
Next
Application.ScreenUpdating = True
End Sub
答案1
假設我們從以下開始:
我們想要重新組織成行,每行的最後一項是新的。這段程式碼:
Sub ReOrg()
Dim i As Long, j As Long, N As Long, K As Long
Dim kk As Long
i = 1
j = 2
K = Cells(Rows.Count, "A").End(xlUp).Row
For kk = 1 To K
Cells(i, j).Value = Cells(kk, 1).Value
j = j + 1
If Cells(kk, 1).Value = "New" Then
i = i + 1
j = 2
End If
Next kk
End Sub
將產生: