+ Reply to Thread
Results 1 to 6 of 6

Merging 2 columns into 1 sequentially.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    113

    Merging 2 columns into 1 sequentially.

    How would you merge 2 columns into 1 sequentially? Column A is DATE and column B is DAY of YEAR. I want to automatically merge the columns into another column with the order A1, B1, A2, B2, A3, B3, etc. I will be working with different kinds of data.

    See attached Excel file.

    Thanks,

    Jim15
    Attached Files Attached Files
    Jim15

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Merging 2 columns into 1 sequentially.

    Hello Jim15,

    In added a button to the worksheet to run the macro below. This has already been added to the attached workbook.
    Sub MergeColumns()
    
      Dim Data(1 To 730, 1 To 1) As Variant
      Dim R As Long
      
        Set Rng = Worksheets("Merge Columns").Range("A2:A366")
         
          For I = 1 To 730 Step 2
            R = R + 1
            Data(I, 1) = R
            Data(I + 1, 1) = Rng.Cells(R, 1).Value
          Next I
        
       Worksheets("Merge Columns").Range("D2:D731").Value = Data
       
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Merging 2 columns into 1 sequentially.

    note this is easily done with copy /paste sort and text to columns!
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Merging 2 columns into 1 sequentially.

    Hello Martin,

    I want to automatically merge the columns into another column
    I don't think doing it manually meets the requirement.

  5. #5
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    113

    Re: Merging 2 columns into 1 sequentially.

    Mr. Ross,

    I actually wanted to merge the columns with any kind of data. The macro does sort sequentially as requested but when I tried with alphabetic characters in both columns it still displayed the result using numbers. Can you modify to handle any kind of data in Columns A and B?

    Thanks,

    Jim15
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Merging 2 columns into 1 sequentially.

    Hello Jim15,

    I changed the macro to use what is in the columns. This has been added to the attached workbook.
    Sub MergeColumns()
    
      Dim Data(1 To 730, 1 To 1) As Variant
      Dim R As Long
      
        Set Rng = Worksheets("Merge Columns").Range("A2:A366")
         
          For I = 1 To 730 Step 2
            R = R + 1
            Data(I, 1) = Rng.Cells(R, 2).Value
            Data(I + 1, 1) = Rng.Cells(R, 1).Value
          Next I
        
       Worksheets("Merge Columns").Range("D2:D731").Value = Data
       
    End Sub
    Attached Files Attached Files

+ 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.6.0 RC 1