我小心翼翼地制定了VBA代碼,我不知道您Excel中的水平。我也照顧到讓代碼儘可能簡單。 在此代碼中(如下所示): 表1是顯示和讀取數據的工作表。 Sheet2是寫入數據的工作表。 RowsColsTransformer()是要運行的過程。
「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這可以幫助。
「這個論壇的任何想法?」太寬泛了。堆棧溢出不是我網站的代碼。請張貼您嘗試過的任何代碼,並具體解釋錯誤,以便我們幫助您克服該特定錯誤。 –
@ScottCraner - 我很抱歉。我相對較新使用Excel來操作大型數據集。對於未來的職位,我會先發布我的努力。 – KGHicks