Populate columns in one column one after one

I

ilyaskazi

In selection.range, multiple columns are selected.

Upon execution, I need this all columns to be populated in one colum
one after one.

For example please see attached file.
FYI, Selection area= Green color cell, Output area=Yellow color cel

+-------------------------------------------------------------------
|Filename: Col-2-Row.zip
|Download: http://www.excelforum.com/attachment.php?postid=3734
+-------------------------------------------------------------------
 
B

Bernie Deitrick

ilyaskazi,

Explain your needs with words - very few people will open your file.

HTH,
Bernie
MS Excel MVP
 
I

ilyaskazi

The only thing i need is to populate all the data of selected multipl
columns in single one column.
Data of column-C, D, E if selected, then populate its data in column-
with first column-C, D and then E.

Kindly requesting you all to see picture file attached, if possible.
m unable to explain more on this issue with words

+-------------------------------------------------------------------
|Filename: Col-2-Row.JPG
|Download: http://www.excelforum.com/attachment.php?postid=3742
+-------------------------------------------------------------------
 
T

T-®ex

Maybe you'll get some ideas from this:

Sub CopyColumnByColumn()
'You should change [ActiveSheet.Range("C1:F7")] to you
selected range
Dim NumColumns As Integer
NumColumns
ActiveSheet.Range("C1:F7").Columns.Count

Dim NumRows As Long
NumRows = ActiveSheet.Range("C1:F7").Rows.Count

Dim ColIndex As Integer
Dim RowIndex As Long
RowIndex = 1 'start at first row

For ColIndex = 1 To NumColumns
ActiveSheet.Range("C1:F7").Columns(ColIndex).Cop
Cells(RowIndex, 1)
RowIndex = RowIndex + NumRows
Next ColIndex
End Sub

hope this helps... :)
 
I

ilyaskazi

Excellent !!!

It is working exactly as wanted for copying column by column

Thankyou T-®ex...

I was trying hard to apply same with copying row by row but fail to do
so.
Can u help me again plz..
 
T

T-®ex

Try the following:


Code
-------------------
'copies the contents of a selection, column by column, to column 'A'
'starting at row 1
Sub CopyColumnByColumn()
Dim SelectedTarget As Range
Dim NumColumns As Integer
Dim NumRows As Long
Dim ColIndex As Integer
Dim RowIndex As Long
Dim ColLocation As Integer

Set SelectedTarget = Selection
NumColumns = SelectedTarget.Columns.Count
NumRows = SelectedTarget.Rows.Count
RowIndex = 1 'start at first row
ColLocation = 1 'copy to column 'A'

For ColIndex = 1 To NumColumns
SelectedTarget.Columns(ColIndex).Copy Cells(RowIndex, ColLocation)
RowIndex = RowIndex + NumRows
Next ColIndex
End Sub

'copies the contents of a selection, row by row, to row 1
'starting at column 'A'
Sub CopyRowByRow()
Dim SelectedTarget As Range
Dim NumColumns As Integer
Dim NumRows As Long
Dim ColIndex As Integer
Dim RowIndex As Long
Dim RowLocation As Long

Set SelectedTarget = Selection
NumColumns = SelectedTarget.Columns.Count
NumRows = SelectedTarget.Rows.Count
ColIndex = 1 'start at first column
RowLocation = 1 'copy to row 1

For RowIndex = 1 To NumRows
SelectedTarget.Rows(RowIndex).Copy Cells(RowLocation, ColIndex)
ColIndex = ColIndex + NumColumns
Next RowIndex
End Sub

'copies the contents of a selection, row by row, to column 'A'
'starting at row 1
Sub CopyRowByRowToColumn()
Dim SelectedTarget As Range
Dim NumColumns As Integer
Dim NumRows As Long
Dim ColIndex As Integer
Dim RowIndex As Long
Dim ColLocation As Integer
Dim CurrentRow As Long

Set SelectedTarget = Selection
NumColumns = SelectedTarget.Columns.Count
NumRows = SelectedTarget.Rows.Count
ColLocation = 1 'copy to column 'A'
CurrentRow = 1 'start at row 1

For RowIndex = 1 To NumRows
For ColIndex = 1 To NumColumns
Cells(CurrentRow, ColLocation).Value = SelectedTarget.Cells(RowIndex, ColIndex).Value
CurrentRow = CurrentRow + 1
Next ColIndex
Next RowIndex
End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top