transfer to single column

bala06

New Member
Joined
May 31, 2011
Messages
39
Dear Excel users

I would like to transfer my data from multiple columns to sinlge column.

The length of the columns is varies and it also contains gaps or some columns are empty.

Kindly adivce.

Many Thanks
Balaji
 

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.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG31May58
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Sheets("Sheet1").Range("A1").CurrentRegion
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
        [COLOR="Navy"]If[/COLOR] Dn <> "" [COLOR="Navy"]Then[/COLOR]
            c = c + 1
            Sheets("sheet3").Range("A" & c) = Dn '[COLOR="Green"][B]Sheet3 = destination Sheet[/B][/COLOR]
        [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Dear Mick

Thanks for help.

It shows error in the line

" Sheets("sheet3").Range("A" & c) = Dn 'Sheet3 = destination Sheet"

many Thanks
Balaji
 
Upvote 0
Make sure you have a sheet of that name.
If not the problem please show an example of your sheet and the approx size of the range.
NB:- To show sheet place a Border around each cell within the range to be copied ,to form a grid. Copy and paste range to the Thread.
Mick
 
Upvote 0
Make sure you have a sheet of that name.
If not the problem please show an example of your sheet and the approx size of the range.
NB:- To show sheet place a Border around each cell within the range to be copied ,to form a grid. Copy and paste range to the Thread.
Mick


Dear Mick

It works.

Many Thanks
Balaji
 
Upvote 0
Dear Mick

It works.

Many Thanks
Balaji
But it is not robust if the following is true:
The length of the columns is varies and it also contains gaps or some columns are empty.
For example, with the following layout, only the blue cells would get copied to Sheet3.

Excel Workbook
ABCD
1gdggjdf
2gsdfgjgfd
3gj
4gf
5g
6dfgf
7hfgdf
8hfgfg
9
Sheet1




Also, I think looping through each cell is a slow way to process this task.

Assuming ..
- your Data is on Sheet1
- data starts in column A
- Sheet3 exists and is where you want the results
.. then I would suggest trying this instead.

<font face=Courier New><br><br><SPAN style="color:#00007F">Sub</SPAN> AllColsToOne()<br>    <SPAN style="color:#00007F">Dim</SPAN> Cols <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, c <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> UR <SPAN style="color:#00007F">As</SPAN> Range<br>    <SPAN style="color:#00007F">Dim</SPAN> wsD <SPAN style="color:#00007F">As</SPAN> Worksheet<br>    <br>    <SPAN style="color:#00007F">Set</SPAN> wsD = Sheets("Sheet3")<br>    wsD.Columns("A").ClearContents<br>    <br>    <SPAN style="color:#00007F">With</SPAN> Sheets("Sheet1")<br>        <SPAN style="color:#00007F">Set</SPAN> UR = .UsedRange<br>        Cols = UR.Columns.Count<br>        <SPAN style="color:#00007F">For</SPAN> c = 1 <SPAN style="color:#00007F">To</SPAN> Cols<br>            Intersect(.Columns(c), UR).Copy Destination:= _<br>                wsD.Range("A" & wsD.Rows.Count).End(xlUp).Offset(1)<br>        <SPAN style="color:#00007F">Next</SPAN> c<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    wsD.Columns("A").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

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