+ Reply to Thread
Results 1 to 18 of 18

Combining data from two columns

Hybrid View

  1. #1
    CLR
    Guest

    Re: Combining data from two columns

    Here's a little mod of PCLIVE's code......

    Sub CombineColumns()
    'This macro will clear the contents of column C, then
    'copy the values from column A to column C, and then
    'append the values in column B to the bottom of that list in column C
    Range("c:c").ClearContents
    Range("A1:" & Range("A65536").End(xlUp).Address).Select
    Selection.Copy
    Range("C1").Select
    ActiveSheet.Paste
    Range("B1:" & Range("B65536").End(xlUp).Address).Select
    Selection.Copy
    Range("C65536").End(xlUp).Select
    Selection.Offset(1, 0).Select
    ActiveSheet.Paste
    End Sub

    Vaya con Dios,
    Chuck, CABGx3



    "dziw" wrote:

    >
    > Bump for help with the code or other suggestions
    >
    >
    > --
    > dziw
    > ------------------------------------------------------------------------
    > dziw's Profile: http://www.excelforum.com/member.php...o&userid=10422
    > View this thread: http://www.excelforum.com/showthread...hreadid=567563
    >
    >


  2. #2
    dziw
    Guest
    Thanks alot. It works.

    I'm not really familiar with coding, so how would I change the references if I'm referring to column A in another worksheet.

  3. #3
    PCLIVE
    Guest

    Re: Combining data from two columns

    Add "Worksheets("SheetName")." to the beginning of the Range References
    and change "Select" for those ones you want to copy, to "Copy". The
    modified code below will copy the specified range from the sheet you
    specify. Please change "SheetName" to the name of the sheet you want to
    copy from. It then pastes to the active sheet. Give it a try.


    Sub CombineColumns()
    'This macro will clear the contents of column C, then
    'copy the values from column A to column C, and then
    'append the values in column B to the bottom of that list in column C
    Range("c:c").ClearContents
    Worksheets("SheetName").Range("A1:" &
    Worksheets("SheetName").Range("A65536").End(xlUp).Address).Copy
    Range("C1").Select
    ActiveSheet.Paste
    Worksheets("SheetName").Range("B1:" &
    Worksheets("SheetName").Range("B65536").End(xlUp).Address).Copy
    Range("C65536").End(xlUp).Select
    Selection.Offset(1, 0).Select
    ActiveSheet.Paste
    End Sub



    "dziw" <dziw.2c0weh_1154707633.0382@excelforum-nospam.com> wrote in message
    news:dziw.2c0weh_1154707633.0382@excelforum-nospam.com...
    >
    > Thanks alot. It works.
    >
    > I'm not really familiar with coding, so how would I change the
    > references if I'm referring to column A in another worksheet.
    >
    >
    > --
    > dziw
    > ------------------------------------------------------------------------
    > dziw's Profile:
    > http://www.excelforum.com/member.php...o&userid=10422
    > View this thread: http://www.excelforum.com/showthread...hreadid=567563
    >




  4. #4
    PCLIVE
    Guest

    Re: Combining data from two columns

    Oops! There was wrap-around on that. Try this code
    "PCLIVE" <pclive@livenet.net> wrote in message
    news:%23mMI4Q%23tGHA.1272@TK2MSFTNGP05.phx.gbl...
    > Add "Worksheets("SheetName")." to the beginning of the Range References
    > and change "Select" for those ones you want to copy, to "Copy". The
    > modified code below will copy the specified range from the sheet you
    > specify. Please change "SheetName" to the name of the sheet you want to
    > copy from. It then pastes to the active sheet. Give it a try.
    >
    >

    Sub CombineColumns()
    'This macro will clear the contents of column C, then
    'copy the values from column A to column C, and then
    'append the values in column B to the bottom of that list in column C

    Range("c:c").ClearContents
    Worksheets("SheetName").Range("A1:" & _
    Worksheets("SheetName").Range("A65536").End(xlUp).Address).Copy
    Range("C1").Select
    ActiveSheet.Paste
    Worksheets("SheetName").Range("B1:" & _
    Worksheets("SheetName").Range("B65536").End(xlUp).Address).Copy
    Range("C65536").End(xlUp).Select
    Selection.Offset(1, 0).Select
    ActiveSheet.Paste
    End Sub
    >
    >
    >
    > "dziw" <dziw.2c0weh_1154707633.0382@excelforum-nospam.com> wrote in
    > message news:dziw.2c0weh_1154707633.0382@excelforum-nospam.com...
    >>
    >> Thanks alot. It works.
    >>
    >> I'm not really familiar with coding, so how would I change the
    >> references if I'm referring to column A in another worksheet.
    >>
    >>
    >> --
    >> dziw
    >> ------------------------------------------------------------------------
    >> dziw's Profile:
    >> http://www.excelforum.com/member.php...o&userid=10422
    >> View this thread:
    >> http://www.excelforum.com/showthread...hreadid=567563
    >>

    >
    >




  5. #5
    dziw
    Guest
    EDIT: ok, saw your update...it works. Thanks again.

    One, last question.

    Let's say I have a series of sheets and Sheet2C refers to Sheet1A & Sheet2B, Sheet3C refers to Sheet2A & Sheet3C. Is there anyway to make it a continuous macro always referring back the the previous sheet for column A, or would I have to repaste a modified code for each new sheet added?

    That might be unclear. What I mean, is in the code instead of typing in the specific spreadsheet, I'd like the worksheet reference for A to be "Previous worksheet" and worksheet reference for B to be "Current worksheet" if that makes more sense.
    Last edited by dziw; 08-04-2006 at 01:24 PM.

  6. #6
    dziw
    Guest
    Bump for help with referencing previous/current sheets.

    Basically, I have a series of months a worksheets, with categories of names in columns. Each month the names shift to different categories, and one category combines names.

    I want to see if I have to write one long code with each month, or a short code that refers to the previous and current worksheet.

  7. #7
    dziw
    Guest
    Having a problem with the code. It was working when copying cells with the names in the actual cell on a sample worksheet.

    But, on the actual worksheet, the names in the cells are references to cells from previous month worksheets. When I run the code like that, it doesn't work properly.

    Any way to change the code?

  8. #8
    Registered User
    Join Date
    01-29-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Combining data from two columns

    Hi, try this combining cells in Excel. You can combine multiple columns into one cell regardless of if you are using formulas or not.

  9. #9
    CLR
    Guest

    Re: Combining data from two columns

    This will get the data from column A on Sheet2 and column B on Sheet3 and
    paste it all in column C on sheet1...........

    Sub CombineColumns()
    'This macro will clear the contents of column C, then
    'copy the values from column A to column C, and then
    'append the values in column B to the bottom of that list in column C
    Worksheets("sheet1").Select 'The sheet where you want the results
    Range("c:c").ClearContents
    Worksheets("sheet2").Select 'The sheet where column A data is
    Range("A1:" & Range("A65536").End(xlUp).Address).Select
    Selection.Copy
    Worksheets("sheet1").Select 'Go back to paste the data
    Range("C1").Select
    ActiveSheet.Paste
    Worksheets("sheet3").Select 'the sheet where column B data is
    Range("B1:" & Range("B65536").End(xlUp).Address).Select
    Selection.Copy
    Worksheets("sheet1").Select 'go back to paste the data
    Range("C65536").End(xlUp).Select
    Selection.Offset(1, 0).Select
    ActiveSheet.Paste
    Range("c1").Select
    End Sub

    hth
    Vaya con Dios,
    Chuck, CABGx3




    "dziw" wrote:

    >
    > Thanks alot. It works.
    >
    > I'm not really familiar with coding, so how would I change the
    > references if I'm referring to column A in another worksheet.
    >
    >
    > --
    > dziw
    > ------------------------------------------------------------------------
    > dziw's Profile: http://www.excelforum.com/member.php...o&userid=10422
    > View this thread: http://www.excelforum.com/showthread...hreadid=567563
    >
    >


+ 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