Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Multiple Columns to Single Columns

Hi Guys,

I have a spreadsheet which has data in a number of columns which I need
to copy to another sheet in one single column.

What I need to be able to do is select all the columns from the source
sheet (this number may vary), and then have select a start point in
another sheet and ahve all the columns sequentially pasted in.

I've started to write a macro to do this but haven't got very far, can
any help me out?

Thanks

Simon

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Multiple Columns to Single Columns

Try:

Sub CopyAndMerge()

Dim inrange As Range, outrange As Range
Dim cValue as variant
Dim r as long, c as integer

Set inrange = Application.InputBox(prompt:="Select Input range", Type:=8)
Set outrange = Application.InputBox(prompt:="Select Output range", Type:=8)

Do While Application.Or(outrange.Rows.Count < 1, outrange.Columns.Count < 1)
MsgBox "Output range must be a single cell"
Set outrange = Application.InputBox(prompt:="Select Output range", Type:=8)
Loop

For r = 1 To inrange.Rows.Count

Cvalue = ""
For c = 1 To inrange.Columns.Count
Cvalue = Cvalue & inrange(r, c).Value
Next c

outrange.Value = Cvalue

Set outrange = outrange.Offset(1, 0)
Next r
End Sub

HTH

" wrote:

Hi Guys,

I have a spreadsheet which has data in a number of columns which I need
to copy to another sheet in one single column.

What I need to be able to do is select all the columns from the source
sheet (this number may vary), and then have select a start point in
another sheet and ahve all the columns sequentially pasted in.

I've started to write a macro to do this but haven't got very far, can
any help me out?

Thanks

Simon


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Multiple Columns to Single Columns

Sub OneColumnV2()
''''''''''''''''''''''''''''''''''''''''''
'Macro to copy columns of variable length'
'into 1 continous column in a new sheet '
'Modified 17 FEb 2006 by BD
''''''''''''''''''''''''''''''''''''''''''
Dim iLastcol As Long
Dim iLastRow As Long
Dim jLastrow As Long
Dim ColNdx As Long
Dim Ws As Worksheet
Dim myRng As Range
Dim ExcludeBlanks As Boolean
Dim mycell As Range

ExcludeBlanks = (MsgBox("Exclude Blanks", vbYesNo) = vbYes)
Set Ws = ActiveSheet
iLastcol = Ws.Cells(1, Ws.Columns.Count).End(xlToLeft).Column
On Error Resume Next

Application.DisplayAlerts = False
Worksheets("Alldata").Delete
Application.DisplayAlerts = True

Sheets.Add.Name = "Alldata"

For ColNdx = 1 To iLastcol

iLastRow = Ws.Cells(Ws.Rows.Count, ColNdx).End(xlUp).Row

Set myRng = Ws.Range(Ws.Cells(1, ColNdx), _
Ws.Cells(iLastRow, ColNdx))

If ExcludeBlanks Then
For Each mycell In myRng
If mycell.Value < "" Then
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next mycell
Else
myRng.Copy
jLastrow = Sheets("Alldata").Cells(Rows.Count, 1) _
.End(xlUp).Row
mycell.Copy
Sheets("Alldata").Cells(jLastrow + 1, 1) _
.PasteSpecial xlPasteValues
End If
Next

Sheets("Alldata").Rows("1:1").EntireRow.Delete

Ws.Activate
End Sub


Gord Dibben MS Excel MVP

On 6 Sep 2006 09:50:11 -0700, wrote:

Hi Guys,

I have a spreadsheet which has data in a number of columns which I need
to copy to another sheet in one single column.

What I need to be able to do is select all the columns from the source
sheet (this number may vary), and then have select a start point in
another sheet and ahve all the columns sequentially pasted in.

I've started to write a macro to do this but haven't got very far, can
any help me out?

Thanks

Simon


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Multiple Columns to Single Columns

...misread your post .....try this:

Sub CopyAndMerge()

Dim inrange As Range, outrange As Range
Dim cValue As Variant
Dim r As Long, c As Integer


Set inrange = Application.InputBox(prompt:="Select Input range", Type:=8)
Set outrange = Application.InputBox(prompt:="Select Output range", Type:=8)


Do While Application.Or(outrange.Rows.Count < 1, outrange.Columns.Count < 1)
MsgBox "Output range must be a single cell"
Set outrange = Application.InputBox(prompt:="Select Output range", Type:=8)
Loop


For r = 1 To inrange.Rows.Count

For c = 1 To inrange.Columns.Count
outrange.Value = inrange(r, c).Value
Set outrange = outrange.Offset(1, 0)
Next c

Next r
End Sub

"Toppers" wrote:

Try:

Sub CopyAndMerge()

Dim inrange As Range, outrange As Range
Dim cValue as variant
Dim r as long, c as integer

Set inrange = Application.InputBox(prompt:="Select Input range", Type:=8)
Set outrange = Application.InputBox(prompt:="Select Output range", Type:=8)

Do While Application.Or(outrange.Rows.Count < 1, outrange.Columns.Count < 1)
MsgBox "Output range must be a single cell"
Set outrange = Application.InputBox(prompt:="Select Output range", Type:=8)
Loop

For r = 1 To inrange.Rows.Count

Cvalue = ""
For c = 1 To inrange.Columns.Count
Cvalue = Cvalue & inrange(r, c).Value
Next c

outrange.Value = Cvalue

Set outrange = outrange.Offset(1, 0)
Next r
End Sub

HTH

" wrote:

Hi Guys,

I have a spreadsheet which has data in a number of columns which I need
to copy to another sheet in one single column.

What I need to be able to do is select all the columns from the source
sheet (this number may vary), and then have select a start point in
another sheet and ahve all the columns sequentially pasted in.

I've started to write a macro to do this but haven't got very far, can
any help me out?

Thanks

Simon


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
lookup across multiple columns NHP Excel Worksheet Functions 4 March 31st 06 10:31 PM
filtering unique in multiple columns umniy Excel Worksheet Functions 4 March 9th 06 01:06 PM
Formula to delete blank cells across multiple columns? SamFunMail Excel Worksheet Functions 2 September 1st 05 07:05 AM
Convert 1 row of data into Multiple columns Mohoney Excel Discussion (Misc queries) 1 August 25th 05 12:36 PM
Hiding multiple columns MDavis Excel Discussion (Misc queries) 1 July 25th 05 08:46 PM


All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"