How to convert multiple rows into a single row

mcva

New Member
Joined
Apr 20, 2020
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hello, I´m beginning to learn vba, and I just can´t solve this one. If someone can help me...thank you
I have several excel worksheets that approximatly 7336 rows filed with groups of numbers with different column and row length.
The output I need is below. Basically inside each group all rows are aligned.
I have used without success the code below. I just can´t make it go trough all the groups
Thank you


Excel_project.jpg


VBA Code:
[CODE=vba]Sub convertMultipleRowsToOneRow()
    Set myRange = Application.InputBox("select one range that you want to convert:", "", Type:=8)
    Set dRang = Application.InputBox("Select one Cell to place data:", "", Type:=8)
    rowNum = myRange.Rows.Count
    colNum = myRange.Columns.Count
    For i = 1 To rowNum
        myRange.Rows(i).Copy dRang
        Set dRang = dRang.Offset(0, colNum + 0)
    Next
End Sub
[/CODE]
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
@mcva
Your code is asking for a range to be selected. Does that mean you want to be able to convert part, rather than the whole list?
Similarly, you are wanting to select a start cell for the converted data?
Always a blank row between groups?
Is there a likely max number of numbers (columns) in any one line of the original?
Is row 1 of your Output, above, missing 8,6,8?
Can you please clarify
 
Upvote 0
Hello thank you,
I need to convert the whole list... and not only a selected range.
Yes always a blank row between groups
No there is no max number of colums or rows inside each group...the empty space line is the reference
yes it is missing 8,6,8
 
Upvote 0
Another question. Are you looking to create the new yet preserve the original list?
 
Upvote 0
Give the below macro a try …

VBA Code:
Sub PrepareList()

Dim a As Variant, b As Variant, r&, c&
a = ActiveSheet.UsedRange

ReDim b(1 To UBound(a), 1 To (UBound(a) * UBound(a, 2)))
r = 1: c = 1
For x = 1 To UBound(a)
    For y = 1 To UBound(a, 2)
        If a(x, 1) = "" Then
            r = r + 1
            c = 1
            Exit For
        ElseIf a(x, y) = "" Then
            Exit For
        Else
            b(r, c) = a(x, y)
            c = c + 1
        End If
    Next y
Next x

Sheets.Add(after:=Sheets(Sheets.Count)).Range("A1").Resize(UBound(b), UBound(b, 2)) = b

End Sub
 
Upvote 0
Give the below macro a try …

VBA Code:
Sub PrepareList()

Dim a As Variant, b As Variant, r&, c&
a = ActiveSheet.UsedRange

ReDim b(1 To UBound(a), 1 To (UBound(a) * UBound(a, 2)))
r = 1: c = 1
For x = 1 To UBound(a)
    For y = 1 To UBound(a, 2)
        If a(x, 1) = "" Then
            r = r + 1
            c = 1
            Exit For
        ElseIf a(x, y) = "" Then
            Exit For
        Else
            b(r, c) = a(x, y)
            c = c + 1
        End If
    Next y
Next x

Sheets.Add(after:=Sheets(Sheets.Count)).Range("A1").Resize(UBound(b), UBound(b, 2)) = b

End Sub
I´m getting "out of memory"
 
Upvote 0
What is the maximum number of columns you data might extend to ? 10 ? 15 ? And what about maximum number of rows per set
 
Upvote 0
Yes, when I tried with a larger sample I got the same error that's why I am asking 2 questions in post # 8 so I can rectify the issue :)
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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