Consulting

Results 1 to 10 of 10

Thread: Solved: COmbine columns

  1. #1

    Exclamation Solved: COmbine columns

    Hello. I have a problem I need to resolve.
    I have 2 worksheets with data. (aprox 40 columns each)
    The names of the columns are 1-a 2-a 3-a 4-a 5-a, etc... on one of the worksheets and 1-b, 2-b, 3-b, 4-b, etc... on the other worksheet. What I need to do is a new worksheet with columns combining the data of each of the worksheets . I mean I need a new worksheet with this information order
    1-a, 1-b, 2-a, 2-b, 3-a, 3-b, etc... (I would like to get a quick solution, no just copy and paste because the data base is so big, so it takes a lof of time)

    Any suggestion?
    I really appreciate you help..

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Try the attached workbook.

    To use, select the cells in the columnsyou want to combine. For example, if you wanted to combine A1,B1,C1 the select A1:C1, then run the macro. Will put all cell contents in the left most column.
    Peace of mind is found in some of the strangest places.

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi,
    Welcome to VBAX
    Try the following. It assumed Data in Sheet1 and Sheet2, combining into Sheet3. It also assumes equal data columns in both sheets
    [VBA]Option Explicit

    Sub JoinData()
    Dim i As Long, Cols As Long

    Application.ScreenUpdating = False
    Sheets("Sheet1").Activate
    Cells.Copy
    Sheets("sheet3").Activate
    Range("A1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Cols = Sheets("Sheet3").[IV1].End(xlToLeft).Column
    For i = Cols To 2 Step -1
    Cells(1, i).EntireColumn.Insert
    Next
    For i = 1 To Cols
    Sheets("Sheet2").Activate
    Columns(i).Copy
    Sheets("sheet3").Activate
    Cells(1, 2 * i).Select
    ActiveSheet.Paste
    Next
    Application.CutCopyMode = False
    Application.ScreenUpdating = True

    End Sub[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Boy I misread that one!!
    Peace of mind is found in some of the strangest places.

  5. #5
    Thank you for your help.
    I have a problem on (Range("A1").Select ), it is giving me error 1004. Can you help me to fix it please!!!!

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post your workbook with sanitized data. To post it, use Manage Attachments which you'll find in the Go Attached option.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7

    sample

    Ok, let's say I have info on worksheets 1 and 2.
    I need to copy all that information to worksheet 3 in this order:
    data on:
    a-1 a-2 b-1 b-2 c-1 c-2, etc... in different columns!!

    Thank you

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I can see no problem with the code and have to suspect some workbook corruption. Try this version. I added a button for ease of use and a final A1 select, otherwise things are the same.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    I really appreciate your help. It worked fantastic.

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Glad to help out.

    If you're happy with the answer, please mark the thread solved usiing the thread tools dropdown, or else let us know of any queries
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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