View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
AltaEgo AltaEgo is offline
external usenet poster
 
Posts: 245
Default Many columns value in to one column one after another

Cannot recall who posted the original code to give credit where due but here
is my modified version of a sub that changes a matrix to a column.

Paste the sub to a new module and run it. Experiment first in a test
workbook to become familiar with its operation and to check that this is
what you want.

If you are inexperienced with VBA:

Press Alt/F11
Click Insert, Module
Paste the Sub at the bottom of my message.

Run it from your Macro menu.

To achieve what you wish:
Run the macro
Select the range of data to be transposed when prompted an press enter
Select the top cell where you want the column to start
Choose "no" to the question "do you wish to transpose across rows first"

In relation to the above, "yes" would result in a column ordered
a,d,g,b,e,h,c,f


Sub Matrix2Column()
Dim v As Variant
Dim nCol As Long
Dim nRow As Long
Dim rOut As Range
Dim iCol As Long

On Error Resume Next
v = Application.InputBox("Select range to copy", Type:=8).Value

If IsEmpty(v) Then Exit Sub


nRow = UBound(v, 1)
nCol = UBound(v, 2)

Set rOut = Application.InputBox("Select destination",
Type:=8).Resize(nRow, 1)
If rOut Is Nothing Then Exit Sub

Select Case MsgBox("Do you wish to transpose across rows first?",
vbYesNo Or vbExclamation Or vbSystemModal Or vbDefaultButton1,
"Row-by-row?")
Case vbYes
v = WorksheetFunction.Transpose(v)
Case vbNo

End Select

For iCol = 1 To nCol
rOut.Value = WorksheetFunction.Index(v, 0, iCol)
Set rOut = rOut.Offset(nRow)
Next iCol
End Sub

--
Steve

"Anex" wrote in message
...
Hello,
I have a large data like this in an excel sheet
A D G
B E H
C F

I want to change in it to one column like this

A
B
C
D
E
F
G
H

Any function or formula please?