I have a long set of information in columns, sometimes hundreds of rows (This is being generated via VBA). I need to transpose this AND save it as a CSV (as excel would run out of columns).
A screenshot of the table is attached.
Any help is appreciated in advance.
Question has been answered in two different ways. Am sure it will be valuable to many other people.
解决方案
You take some code to export to CSV, such as from this answer
How to create a separate CSV file from VBA?
and just change the order you write to the file. E.g. write the column before writing the row
Sub WriteFile()
Dim ColNum As Integer
Dim Line As String
Dim LineValues() As Variant
Dim OutputFileNum As Integer
Dim PathName As String
Dim RowNum As Integer
Dim SheetValues() As Variant
PathName = Application.ActiveWorkbook.Path
OutputFileNum = FreeFile
Open PathName & "\Test.csv" For Output Lock Write As #OutputFileNum
'Print #OutputFileNum, "Field1" & "," & "Field2"
SheetValues = Sheets("RawData").Range("A1:C249").Value
Dim RowMax
RowMax = UBound(SheetValues)
Dim ColMax
ColMax = 3
ReDim LineValues(1 To RowMax)
For ColNum = 1 To ColMax
For RowNum = 1 To RowMax
LineValues(RowNum) = SheetValues(RowNum, ColNum)
Next
Line = Join(LineValues, ",")
Print #OutputFileNum, Line
Next
Close OutputFileNum
End Sub
Hopefully that is a good enough to get you going.