Transpose multiple rows and columns into one column with ignoring blanks

parankush

New Member
Joined
Jun 11, 2020
Messages
36
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
i want to Transpose multiple rows and columns into one column with ignoring blanks. I have a large amount of data. But i can provide with a sample.Is there any VBA code i can use for it.
1591894818027.png
 
I have no problems with 100,000 and DZ column.
Run the macro in post #17 again and tell me it appears in the msgbox.


Okay.

I got the error after running it 15-20 times.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
It is undoubtedly a memory problem for your machine and your excel. As I told you I have no problems with 100,000 lines and columns up to DZ.
You will have to perform executions, exit excel, to clean the memory of your machine and return to executions.

Try this

VBA Code:
Sub Transpose_99()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  Dim lr As Long, lc As Long
  '
  With Sheets("Sheet1")
    a = Range("A1:A2").Value2
    b = Range("A1:A2").Value2
    Erase a, b
    lr = .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
    lc = .Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
    a = .Range("A1", .Cells(lr, lc)).Value2
  End With
  
  ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 1)
  '
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If a(i, j) <> "" Then
        k = k + 1
        b(k, 1) = a(i, j)
      End If
    Next
  Next
  Sheets("Sheet2").Range("A1").Resize(k).Value = b
  Erase a, b
End Sub
 
Upvote 0
Could you comment:
  1. Why do you run it multiple times?
  2. Do you have other macros running?
  3. Do you have formulas on your sheets?
  4. Do you have conditional formats on your sheets?
 
Upvote 0
Another attempt to help the process

VBA Code:
Sub Transpose_5()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  Dim lr As Long, lc As Long
  '
  With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
    .Calculation = xlCalculationManual
  End With
  
  With Sheets("Sheet1")
    a = Range("A1:A2").Value2
    b = Range("A1:A2").Value2
    Erase a, b
    lr = .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
    lc = .Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
    a = .Range("A1", .Cells(lr, lc)).Value2
  End With
  MsgBox "Rows : " & UBound(a, 1) & " Cols: " & UBound(a, 2) & vbCr & "Press Enter to continue"
  ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 1)
  '
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If a(i, j) <> "" Then
        k = k + 1
        b(k, 1) = a(i, j)
      End If
    Next
  Next
  Sheets("Sheet2").Range("A1").Resize(k).Value = b
  Erase a, b
  With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .DisplayAlerts = True
    .Calculation = xlCalculationAutomatic
    .CutCopyMode = False
  End With
End Sub
 
Upvote 0
Solution
Could you comment:
  1. Why do you run it multiple times?
  2. Do you have other macros running?
  3. Do you have formulas on your sheets?
  4. Do you have conditional formats on your sheets?


1.Because I receive the data in which I need this.
2. No, only one macro is running.
3.NO, No formulas.
4.No.
 
Upvote 0
Also try the following:

VBA Code:
Sub Transpose_2()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  Dim lr As Long, lc As Long
  '
  With Sheets("Sheet1")
    lr = .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
    lc = .Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
    a = .Range("A1", .Cells(lr, lc)).Value2
  End With
  MsgBox "Rows : " & UBound(a, 1) & " Cols: " & UBound(a, 2) & vbCr & "Press Enter to continue"
  ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 1)
  '
  For i = 1 To UBound(a, 1)
    For j = 1 To UBound(a, 2)
      If a(i, j) <> "" Then
        k = k + 1
        b(k, 1) = a(i, j)
      End If
    Next
  Next
  Sheets("Sheet2").Range("A1").Resize(k).Value = b
  Erase a, b
End Sub

I got an error.
here is the Pic of it.
 

Attachments

  • WhatsApp Image 2020-06-20 at 20.35.20.jpeg
    WhatsApp Image 2020-06-20 at 20.35.20.jpeg
    51.6 KB · Views: 14
Upvote 0
That is not the new macro of post #25.
In addition to the pic to see the macro line with the error, you must put the error message.

That is an error of macro in tread No.#17
The error message is "OUT of memory" and then after clicking on debug we get that screen with highlighted line.
 
Upvote 0
So I put the macro in post #25 so you can test the macro in post #25.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top