+ Reply to Thread
Results 1 to 3 of 3

Thread: Merging 2 columns into 1 alternating every other column

  1. #1
    Registered User
    Join Date
    08-12-2010
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2003
    Posts
    1

    Merging 2 columns into 1 alternating every other column

    I'm looking for a way to put data into 1 column from 2 different columns, alternating every other row.

    The data looks like this:
    A B C
    1 2
    3 4
    5 6

    And I want C to look like this:
    C
    1
    2
    3
    4
    5
    6

    I don't necessarily need to keep the data in columns A and B, as long as C follows this format.

    Thanks!

    **
    Excellent, just what I was looking for. I couldn't get the UDF working right, I'll try messing around with it, but the Index solution works great!

    --Thanks
    Last edited by Cauthon; 08-12-2010 at 03:11 PM. Reason: Solved

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Merging 2 columns into 1 alternating every other column

    Assuming your values commence in A1 then one way

    C1:
    =INDEX($A:$B,CEILING(ROWS(C$1:C1)/2,1),2-MOD(ROWS(C$1:C1),2))
    copied down

  3. #3
    Forum Guru contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2010
    Posts
    1,342

    Re: Merging 2 columns into 1 alternating every other column

    I may late but this one is UDF solution.

    Function MERGECOLS(rng As Range) As Variant
        Dim r, c, CallerRows, CallerCols, iCount As Integer
        Dim TempStr As String
        Dim Result(), cValue As Variant
        
        For c = 1 To rng.Columns.Count
            For r = 1 To rng.Rows.Count
                iCount = iCount + 1
                TempStr = TempStr & " " & Cells(r, c)
            Next r
        Next c
        
        With Application.Caller
            CallerRows = .Rows.Count
            CallerCols = .Columns.Count
        End With
    
        If CallerRows > iCount Or CallerCols > 1 Then
            MERGECOLS = "#RANGE!"
            Exit Function
        End If
    
        cValue = Split(TempStr, " ")
        ReDim Result(1 To CallerRows, 1 To CallerCols)
    
    
        For r = 1 To UBound(cValue)
            Result(r, 1) = cValue(r)
        Next r
    
        MERGECOLS = Result
    End Function
    A	B		Result
    1	4		1
    2	5		2
    3	6		3
    			4
    			5
    			6
    Select whole range C1:C6, press F2 then paste this formula there
    =MERGECOLS(A2:B4)
    Confirm with Ctrl+Shift+Enter.

    Last edited by contaminated; 08-12-2010 at 02:00 PM.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, «Born in USSR»
    Vusal M Dadashev

    Baku, Azerbaijan

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0