how to put each corresponding column in rows to get 1 column-multiple rows?

modiria50989

New Member
Joined
Aug 11, 2017
Messages
32
Hello please help me with this:
I have this:

applered20 max
orangegreen34 min
bananayellow56 max
berryblack76 min
watermelonyellow40 min

<tbody>
</tbody>
I want this:

apple
red
20 max
orange
green
34 min
banana
yellow
56 max
berry
black
76 min
watermelon
yellow
40 min

<tbody>
</tbody>
Thank you.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this with Data from active sheet, to Results on sheet2 column "A".
Code:
[COLOR="Navy"]Sub[/COLOR] MG07Jun49
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = ActiveSheet.Cells(1).CurrentRegion.Resize(, 3)
c = 1
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Rows
    Sheets("Sheet2").Cells(c, 1).Resize(Rng.Columns.Count) = Application.Transpose(Dn.Value)
    c = c + Rng.Columns.Count + 1
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thank you for your code but i get an error that says, Run-time error 9: Subscript out of range.





Try this with Data from active sheet, to Results on sheet2 column "A".
Code:
[COLOR=Navy]Sub[/COLOR] MG07Jun49
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = ActiveSheet.Cells(1).CurrentRegion.Resize(, 3)
c = 1
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng.Rows
    Sheets("Sheet2").Cells(c, 1).Resize(Rng.Columns.Count) = Application.Transpose(Dn.Value)
    c = c + Rng.Columns.Count + 1
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Upvote 0
This works great thank you! One more question please. In reality some of the rows have more than 3 columns. For example if I have a 4 column and a 6 column row then I have to change "3" to "6" in your code (...CurrentRegion.Resize(, 3)), but at the end I see more empty rows (instead of just one empty row) between each group. Is it possible to make sure I have only one empty row between each group?

I hope I could be clear on my question.
Thank you again.

 
Upvote 0
Try this, It should cater for various numbers of columns with data.
Code:
[COLOR="Navy"]Sub[/COLOR] MG09Jun40
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] cols [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = ActiveSheet.Cells(1).CurrentRegion
c = 1
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Rows
    cols = Application.CountA(Dn)
    Sheets("Sheet2").Cells(c, 1).Resize(cols) = Application.Transpose(Dn.Value)
    c = c + cols + 1
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
I'm getting run time error '9' on this line:
Sheets("Sheet2").Cells(c, 1).Resize(cols) = Application.Transpose(Dn.Value)


Try this, It should cater for various numbers of columns with data.
Code:
[COLOR=Navy]Sub[/COLOR] MG09Jun40
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] cols [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = ActiveSheet.Cells(1).CurrentRegion
c = 1
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng.Rows
    cols = Application.CountA(Dn)
    Sheets("Sheet2").Cells(c, 1).Resize(cols) = Application.Transpose(Dn.Value)
    c = c + cols + 1
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Upvote 0
Have you got a Sheet named "Sheet2" in your workbook ????
 
Last edited:
Upvote 0
Wait, actually works very well! thank you!
Instead of copy paste your code I typed that out and worked. Thanks again, you're awesome!

Try this, It should cater for various numbers of columns with data.
Code:
[COLOR=Navy]Sub[/COLOR] MG09Jun40
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] cols [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = ActiveSheet.Cells(1).CurrentRegion
c = 1
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng.Rows
    cols = Application.CountA(Dn)
    Sheets("Sheet2").Cells(c, 1).Resize(cols) = Application.Transpose(Dn.Value)
    c = c + cols + 1
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,216,137
Messages
6,129,093
Members
449,486
Latest member
malcolmlyle

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