I need to convert data from horisontal to vertical to be able to analyse data in a pivot-table.
I found some help in this article: http://www.mrexcel.com/articles/pivot-table-horizontal-to-vertical.php
Where the following code is mentioned:
Public Sub TransformData()
' Copyright 1999 MrExcel.com
Sheets("Sheet2").Select
Range("A1").CurrentRegion.Clear
Sheets("Sheet1").Select
Range("A1:B1").Copy Destination:=Sheets("Sheet2").Range("A1")
Sheets("Sheet2").Select
Range("C1").Value = "Qtr"
Range("D1").Value = "Sales"
Sheets("Sheet1").Select
FinalRow = Range("A16000").End(xlUp).Row
NextRow = 2
LastRow = FinalRow
' Loop through the data columns
For i = 3 To 6
ThisCol = Mid("ABCDEFGHIJK", i, 1)
' Copy the left columns from sheet1 to sheet2
Range("A2:B" & FinalRow).Copy Destination:= _
Sheets("Sheet2").Range("A" & NextRow)
' Copy the header from ThisCol to column C
Range(ThisCol & "1").Copy Destination:= _
Sheets("Sheet2").Range("C" & NextRow & ":C" & LastRow)
' Copy the data for this quarter to column D
Range(ThisCol & "2:" & ThisCol & FinalRow).Copy _
Destination:=Sheets("Sheet2").Range("D" & NextRow)
NextRow = LastRow + 1
LastRow = NextRow + FinalRow - 2
Next i
Sheets("Sheet2").Select
End Sub
It is the part: For i = 3 To 6 ThisCol = Mid("ABCDEFGHIJK", i, 1)
that is the problem for me as my data is in 32 colums (ie. For i = 2 To 32), but I can only get the Mid("ABC...Z", i, 1) to work for 26 colums, and I need som more.
Does anybody have an idea how to solve my problem?
Best regards
HMR
I found some help in this article: http://www.mrexcel.com/articles/pivot-table-horizontal-to-vertical.php
Where the following code is mentioned:
Public Sub TransformData()
' Copyright 1999 MrExcel.com
Sheets("Sheet2").Select
Range("A1").CurrentRegion.Clear
Sheets("Sheet1").Select
Range("A1:B1").Copy Destination:=Sheets("Sheet2").Range("A1")
Sheets("Sheet2").Select
Range("C1").Value = "Qtr"
Range("D1").Value = "Sales"
Sheets("Sheet1").Select
FinalRow = Range("A16000").End(xlUp).Row
NextRow = 2
LastRow = FinalRow
' Loop through the data columns
For i = 3 To 6
ThisCol = Mid("ABCDEFGHIJK", i, 1)
' Copy the left columns from sheet1 to sheet2
Range("A2:B" & FinalRow).Copy Destination:= _
Sheets("Sheet2").Range("A" & NextRow)
' Copy the header from ThisCol to column C
Range(ThisCol & "1").Copy Destination:= _
Sheets("Sheet2").Range("C" & NextRow & ":C" & LastRow)
' Copy the data for this quarter to column D
Range(ThisCol & "2:" & ThisCol & FinalRow).Copy _
Destination:=Sheets("Sheet2").Range("D" & NextRow)
NextRow = LastRow + 1
LastRow = NextRow + FinalRow - 2
Next i
Sheets("Sheet2").Select
End Sub
It is the part: For i = 3 To 6 ThisCol = Mid("ABCDEFGHIJK", i, 1)
that is the problem for me as my data is in 32 colums (ie. For i = 2 To 32), but I can only get the Mid("ABC...Z", i, 1) to work for 26 colums, and I need som more.
Does anybody have an idea how to solve my problem?
Best regards
HMR