Question : Convert Rows of Data across Multiple Columns into Single Column

Is there an easy way to convert rows of data across multiple columns into a single column of data? I need to calculate values for and then create a text loadfile that can be imported into another application.

Here's an example of the original spreadsheet:

ALPHA01   |ALPHA02   |ALPHA03   |ALPHA04   |
BETA01     |BETA02     |BETA03     |BETA04     |
GAMMA04  |GAMMA04  |GAMMA04  |GAMMA04  |

To be converted into a single column of values as follows:

ALPHA01
ALPHA02
ALPHA03
ALPHA04
BETA01
BETA02
BETA03
BETA04
GAMMA01
GAMMA02
GAMMA03
GAMMA04

Each row must be converted into a column of data followed by the next row of data. I seem to recall a simple way of doing this, but I haven't been able to figure it out.

I have to do this to about 50 spreadsheets, so any ideas would be greatly appreciated.

Answer : Convert Rows of Data across Multiple Columns into Single Column

Hi John,
If you want to do this to specific ranges of cells, try this:

Sub TransposeIntoOneColumn()
    Dim rngInput As Range, rngOutput As Range
    Dim varInput, avarOutput() As Variant
    Dim lngRowCount As Long, lngColumnCount As Long, lngRow As Long, lngCol As Long
    Set rngInput = Application.InputBox(prompt:="Select input range", Type:=8)
    If rngInput Is Nothing Then Exit Sub
    Set rngOutput = Application.InputBox(prompt:="Select top left cell for destination", Title:="Select output cell", Type:=8)
    If rngOutput Is Nothing Then Exit Sub
    Set rngOutput = rngOutput.Cells(1, 1)
    varInput = rngInput
    lngRowCount = UBound(varInput, 1)
    lngColumnCount = UBound(varInput, 2)
    ReDim avarOutput(1 To (lngRowCount * lngColumnCount), 1 To 1)
    For lngRow = 1 To lngRowCount
        For lngCol = 1 To lngColumnCount
            avarOutput((lngColumnCount * (lngRow - 1) + lngCol), 1) = varInput(lngRow, lngCol)
        Next lngCol
    Next lngRow
    Set rngOutput = rngOutput.Resize(lngRowCount * lngColumnCount)
    rngOutput = avarOutput
End Sub


HTH
Rory
Random Solutions  
 
programming4us programming4us