TEJAS NIMBALKAR
asked on
Transpose macro error
Hello Guys,
I am getting an error in the following macro. My macro transforms all Vertical Values to horizontal Formatt. Eg:_
1 A B C
2 B E F
then Output is
1 A
1 B
1 C
2 B
2 E
2 F
But when I try to insert a sheet of 69 columns and 26000 rows it gives runtime error '1004' Below is the code.
Dim a As Variant, b As Variant
Dim i As Long, ii As Long, c As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")
a = .Cells(1).CurrentRegion
ReDim b(1 To (UBound(a, 1) - 1) * (UBound(a, 2) - 1), 1 To 3)
End With
For i = 2 To UBound(a, 1)
For c = 2 To UBound(a, 2)
ii = ii + 1
b(ii, 1) = a(i, 1)
b(ii, 2) = a(1, c)
b(ii, 3) = a(i, c)
Next c
Next i
If Not Evaluate("ISREF(Sheet2!A1) ") Then Worksheets.Add(After:=Shee ts("Sheet1 ")).Name = "Sheet2"
With Sheets("Sheet2")
.UsedRange.ClearContents
.Cells(1).Resize(UBound(b, 1), UBound(b, 2)) = b
.Columns.AutoFit
.Activate
End With
Application.ScreenUpdating = True
End Sub
its gives error for the following line:
.Cells(1).Resize(UBound(b, 1), UBound(b, 2)) = b
Can anybody help me with this?
I am getting an error in the following macro. My macro transforms all Vertical Values to horizontal Formatt. Eg:_
1 A B C
2 B E F
then Output is
1 A
1 B
1 C
2 B
2 E
2 F
But when I try to insert a sheet of 69 columns and 26000 rows it gives runtime error '1004' Below is the code.
Dim a As Variant, b As Variant
Dim i As Long, ii As Long, c As Long
Application.ScreenUpdating
With Sheets("Sheet1")
a = .Cells(1).CurrentRegion
ReDim b(1 To (UBound(a, 1) - 1) * (UBound(a, 2) - 1), 1 To 3)
End With
For i = 2 To UBound(a, 1)
For c = 2 To UBound(a, 2)
ii = ii + 1
b(ii, 1) = a(i, 1)
b(ii, 2) = a(1, c)
b(ii, 3) = a(i, c)
Next c
Next i
If Not Evaluate("ISREF(Sheet2!A1)
With Sheets("Sheet2")
.UsedRange.ClearContents
.Cells(1).Resize(UBound(b,
.Columns.AutoFit
.Activate
End With
Application.ScreenUpdating
End Sub
its gives error for the following line:
.Cells(1).Resize(UBound(b,
Can anybody help me with this?
ASKER
Can u please help me with the steps how to do the same thing in Power Query.
Hi,
Please find the attached file which contains the Power Query Solution, the Query source is range named as Rng.
Unpivot-Columns-Power-Query.xlsx
Please find the attached file which contains the Power Query Solution, the Query source is range named as Rng.
Unpivot-Columns-Power-Query.xlsx
ASKER
its difficult to understand what you have shared.
Hi,
Most of times it's not easy to understand things you never used before immediately, just remember 1st time you used Excel!
Watch the 1st Video from below YouTube playlist link I am sure you will know how to use Power Query.
https://www.youtube.com/watch?v=7Vn6uOxcAc0&list=PLHYaVuyjhcqyYD7qss7lsFVBLf8B_zZrx
Most of times it's not easy to understand things you never used before immediately, just remember 1st time you used Excel!
Watch the 1st Video from below YouTube playlist link I am sure you will know how to use Power Query.
https://www.youtube.com/watch?v=7Vn6uOxcAc0&list=PLHYaVuyjhcqyYD7qss7lsFVBLf8B_zZrx
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
I think this error happen because you are exceeding the number of cells in Excel file the result will be 1,664,000 rows while maximum rows in excel is 1,048,576 only. If your excel has Power Query then this will be very easy task to do.