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
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi and welcome to MrExcel

You could provide the same example but the result you want.
Use XL2BB tool, look at my signature.
 
Upvote 0
Is this what you are looking for? If not, provide as Dante suggested your expected output. Use XL2BB

Book1
ABC
1MonthAttributeValue
2JanB6
3JanC11
4FebA3
5FebB9
6FebC15
7A5
8C5
9AprA7
10AprB12
11AprC4.333333
12MayA9
13MayB15
14MayC1.333333
15JunA11
16JunC-1.66667
Sheet2
 
Upvote 0
Yeah...! Sorry for the incomplete data.
So ,I want this Input data.
1591923846062.png

Converted like this.
1591923895030.png
 
Upvote 0
Assuming column F is free to write the converted data to, and that the data starts in A1 (Month) and there are no completely empty rows in it, try this:
VBA Code:
Sub DataTranspose()
Dim R As Range, Vin As Variant, Vrw As Variant, Vout As Variant, i As Long, NxRw As Long
Set R = Range("A1").CurrentRegion
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
Application.ScreenUpdating = False
For i = 1 To UBound(Vin, 1)
    Vrw = R.Rows(i).Value
    Vout = Application.Transpose(Vrw)
    NxRw = IIf(IsEmpty(Range("F1")), 1, Range("F" & Rows.Count).End(xlUp).Row + 1)
    Range("F" & NxRw).Resize(UBound(Vrw, 2), 1).Value = Vout
Next i
With Columns("F")
    On Error Resume Next
        .SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
    On Error GoTo 0
    .AutoFit
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Assuming column F is free to write the converted data to, and that the data starts in A1 (Month) and there are no completely empty rows in it, try this:
VBA Code:
Sub DataTranspose()
Dim R As Range, Vin As Variant, Vrw As Variant, Vout As Variant, i As Long, NxRw As Long
Set R = Range("A1").CurrentRegion
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
Application.ScreenUpdating = False
For i = 1 To UBound(Vin, 1)
    Vrw = R.Rows(i).Value
    Vout = Application.Transpose(Vrw)
    NxRw = IIf(IsEmpty(Range("F1")), 1, Range("F" & Rows.Count).End(xlUp).Row + 1)
    Range("F" & NxRw).Resize(UBound(Vrw, 2), 1).Value = Vout
Next i
With Columns("F")
    On Error Resume Next
        .SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
    On Error GoTo 0
    .AutoFit
End With
Application.ScreenUpdating = True
End Sub






No No. The data I have is very large. so the data is in sheet one and I want the result in sheet 2. So I will get the result from the above code??
 
Upvote 0
No No. The data I have is very large. so the data is in sheet one and I want the result in sheet 2. So I will get the result from the above code??
OK, then assuming Sheet2 already exists and has column A empty to receive the converted data, try running this when the raw data sheet is the activesheet:
VBA Code:
Sub DataTranspose()
Dim R As Range, Vin As Variant, Vrw As Variant, Vout As Variant, i As Long, NxRw As Long
Set R = Range("A1").CurrentRegion
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
Application.ScreenUpdating = False
For i = 1 To UBound(Vin, 1)
    Vrw = R.Rows(i).Value
    Vout = Application.Transpose(Vrw)
    NxRw = IIf(IsEmpty(Sheets("Sheet2").Range("A1")), 1, Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row + 1)
    Sheets("Sheet2").Range("A" & NxRw).Resize(UBound(Vrw, 2), 1).Value = Vout
Next i
With Sheets("Sheet2").Columns("A")
    On Error Resume Next
        .SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
    On Error GoTo 0
    .AutoFit
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
OK, then assuming Sheet2 already exists and has column A empty to receive the converted data, try running this when the raw data sheet is the activesheet:
VBA Code:
Sub DataTranspose()
Dim R As Range, Vin As Variant, Vrw As Variant, Vout As Variant, i As Long, NxRw As Long
Set R = Range("A1").CurrentRegion
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
Application.ScreenUpdating = False
For i = 1 To UBound(Vin, 1)
    Vrw = R.Rows(i).Value
    Vout = Application.Transpose(Vrw)
    NxRw = IIf(IsEmpty(Sheets("Sheet2").Range("A1")), 1, Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row + 1)
    Sheets("Sheet2").Range("A" & NxRw).Resize(UBound(Vrw, 2), 1).Value = Vout
Next i
With Sheets("Sheet2").Columns("A")
    On Error Resume Next
        .SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
    On Error GoTo 0
    .AutoFit
End With
Application.ScreenUpdating = True
End Sub



It is showing an error.
1591927855511.png


After Clicking in Debug it is showing
1591927891929.png


Please Help
 
Upvote 0
Here are a couple of macros for your consideration.
Assume that your data is on sheet1 starting in cell A1, the results on sheet2.

VBA Code:
Sub Transpose_1()
  Dim c As Range
  Application.ScreenUpdating = False
  For Each c In Sheets("Sheet1").Range("A1").CurrentRegion.SpecialCells(xlCellTypeConstants)
    Sheets("Sheet2").Range("A" & Rows.Count).End(3)(2).Value = c.Value
  Next
End Sub


The following macro is longer, but it is faster.
VBA Code:
Sub Transpose_2()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  a = Sheets("Sheet1").Range("A1", Sheets("Sheet1").Range("A1").SpecialCells(xlLastCell)).Value2
  ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 1)
  For j = 1 To UBound(a, 2)
    For i = 1 To UBound(a, 1)
      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
End Sub
 
Upvote 0
A detail emerged, use this code:

VBA Code:
Sub Transpose_2()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  a = Sheets("Sheet1").Range("A1", Sheets("Sheet1").Range("A1").SpecialCells(xlLastCell)).Value2
  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
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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