+ Reply to Thread
Results 1 to 2 of 2

Create macro to copy data using column headings

  1. #1
    Registered User
    Join Date
    10-30-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    1

    Question Create macro to copy data using column headings

    Hello,

    I need a macro that will collect information from different worksheets and consolidates it on one tab.

    In each worksheets, the number of columns is the same, but the number of rows differs. What I need to macro to do is to take the data + column headings from the first of the 5 source files and paste them into the final worksheet.

    For example,

    Worksheet 1

    Ticker date cusip description ratings funds
    aapl 2-Feb-13 aaaaaa apple aaa 1000
    goog 15-Feb-13 bbbbbb google aaa 1500
    yhoo 2-Mar-13 ccccccc yahoo AA 120
    ko 1-May-13 dddddd coke BB+ 125
    GM 12-Jul-13 eeeeee gen mtrs aa 1550


    worksheet 2

    date cusip description ratings funds Ticker
    2-Feb-13 aaaaaa apple aaa 1000 AAPL
    15-Feb-13 bbbbbb google aaa 1500 GOOG
    2-Mar-13 ccccccc yahoo AA 120 YHOO
    1-May-13 dddddd coke BB+ 125 KO
    12-Jul-13 eeeeee gen mtrs aa 1550 GM



    Now in worksheet 3, which will be the final worksheet, I want to create a macro which basially pulls in all the data from different worksheets and paste them in the following order.

    Description Ticker ratings Funds Date Cusip



    This example only has about 5 data sets, the actual file will have thousands of rows. Sheet 1 could have 1000, sheet 2 could have 500 and sheet 3 can have 1500. And this will wary on a monthly basis, which is why I don't want to copy and past the macro. This month I might have 1000 rows and next month I'll have 2000, so the macro will only pick up the 1000 not 2000, if I copy and paste.

    The heading are the same in all the sheets. Can you please help me create a macro which will copy data from the different sheets using column heading and paste them into the my final sheet. So if I have a heading called "Ticker" i want the final sheet to grab all the information from each sheet under "ticker" and past them into the final sheet.

    Also, each work sheet has names (sheet1=BNY sheet 2=UBS..etc..)

    Can you please create a macro and show me where I can insert the names of the heading and sheets.


    Thank you very much for all of your help. I hope I made sense.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Create macro to copy data using column headings

    Hi, zkhan,

    you should consider attaching a sample of your workbook and clarify on what you understand as Source Files when you you are talking about worksheets elsewhere.

    One idea to solve the request: set objects to the destination sheet and each other worksheet in the workbook (excluding the destiantion sheet when looping through the worksheets), loop through the headers in the destination sheet and see if they match anywhere on the other sheets (either by Application.Match or by using Find), get the last used row from that sheet and copy everything from row 2 (assuming that the header is located in row 1) to the last row into the destiantion sheet under the header to the first free row. You would need to make sure that the data stays together (meaning that the data needs to be of equal length in each column to be copied) or you should mention the criteria which will be filled in any sheet for sure to get the information about the first free row for a new sheet in the destination sheet.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy/Paste filtered data from one sheet to another with only matched column headings
    By archerrc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2013, 05:00 PM
  2. Macro for creating column headings and coping data into these cells
    By matthew1404 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-12-2012, 06:42 AM
  3. Replies: 2
    Last Post: 07-01-2012, 12:20 PM
  4. macro: copy data and create worbooks from a column
    By bijnok in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2008, 10:52 AM
  5. Create Headings from Column Data
    By alphag_25 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-02-2006, 05:45 AM

Tags for this Thread

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