1

Using office 2010.
everything is in same sheet.
Data in Column A B C & D can change (increase or decrease daily)


I have 4 column

                            OUTPUT --> IN column F should be 
---A-----B-----C------D---------------------------------------F
   1     5     8     AP                                       1
   2     6     9     BP                                       2
   3     7     1     CD                                       3
   4           5     QW                                       4
                                                              5
                                                              6
                                                              7
                                                              8
                                                              9
                                                              1
                                                              5
                                                              AP
                                                              BP
                                                              CD
                                                              QW

length of columns A B C & D can increase of decrease.

Mowgli
  • 3,422
  • 21
  • 64
  • 88

3 Answers3

1

How about this?

Sub move()
    Dim ws As Worksheet
    Dim outputColumn As Long
    Dim currentColumn As Long
    Dim currentOutputRow As Long

    Set ws = ActiveSheet
    outputColumn = 6 ' column f

    For currentColumn = 1 To 4
        currentOutputRow = ws.Cells(ws.Rows.Count, outputColumn).End(xlUp).Row
        If (currentOutputRow > 1) Then
            currentOutputRow = currentOutputRow + 1
        End If

        ws.Range(ws.Cells(1, currentColumn), ws.Cells(ws.Rows.Count, currentColumn).End(xlUp)).Copy _
            ws.Cells(currentOutputRow, outputColumn)
    Next
End Sub
Joseph
  • 5,070
  • 1
  • 25
  • 26
  • Thanks it work but still few things, it includes row one also, it shouldn't and I know this will totaly mess things up what if it is not A B C D ? if it is I, O, P Q ? – Mowgli Feb 08 '13 at 14:50
  • @Mowgli You can modify it to use rows 2 and on by changing the last line where it copies from `ws.Cells(1, currentColumn)` to `ws.Cells(2, currentColumn)`. For the column issue, you would have to create an array with the columns you need and then loop through that instead of `1 To 4` – Joseph Feb 08 '13 at 18:27
1

use the below. It accepts the range you need to change and will return a vertical array of values. To fill the values use an array formula.

Function ToVector(rng As Range)

    Dim cells()
    ReDim cells(rng.cells.Count)

    Dim i As Double

    For Each cell In rng

        cells(i) = cell
        i = i + 1

    Next cell

    ToVector = Application.WorksheetFunction.Transpose(cells)

End Function
InContext
  • 2,461
  • 12
  • 24
1

With the help of this site get-digital-help.com/

Combine Columns But this is only static.

I converted it to dynamic meaning changing range.

for example I posted A B C D IN F

To make formula more clear will enter formula in Name Manager

BELOW IS DYNAMIC FORMULA FOR EACH COLUMN (goes in name manger)

ALIST = =OFFSET($A$1,0,0,COUNTA($A:$A),1)
BLIST = =OFFSET($B$1,0,0,COUNTA($B:$B),1)
CLIST = =OFFSET($C$1,0,0,COUNTA($C:$C),1)
DLIST = =OFFSET($D$1,0,0,COUNTA($D:$D),1)

FORMULA IN COLUMN F and drag down

  =IFERROR(INDEX(ALIST, ROWS(F$1:$F1)), 
   IFERROR(INDEX(BLIST, ROWS(F$1:$F1)-ROWS(ALIST)), 
   IFERROR(INDEX(CLIST, ROWS(F$1:$F1)-ROWS(ALIST)-ROWS(BLIST)),
   IFERROR(INDEX(DLIST, ROWS(F$1:$F1)-ROWS(ALIST)-ROWS(BLIST)-ROWS(CLIST)),""))))

Screenshot

enter image description here enter image description here

Mowgli
  • 3,422
  • 21
  • 64
  • 88