+ Reply to Thread
Results 1 to 2 of 2

Thread: Pulling data from worksheets, compiling it in CSV file

  1. #1
    Registered User
    Join Date
    02-02-2010
    Location
    Virginia Beach, VA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Question Pulling data from worksheets, compiling it in CSV file

    OK-just spent a little time putting together a mockup of what I am trying to accomplish, please see attached files. Basically, I have a databast that contains many worksheets (the example contains 2), and I need to pull the data listed in the those worksheets and compile it in a single CSV file. In the CSV example I entered one of the worksheets by hand so you could get the idea of what I am trying to do. Thanks in advance for the help!
    Attached Files Attached Files

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004

    Re: Pulling data from worksheets, compiling it in CSV file

    Try this macro

    Sub Test()
    Dim SourceWorkbook As Workbook
    Dim TargetWorkbook As Workbook
    Set SourceWorkbook = ActiveWorkbook
    Workbooks.Add
    Set TargetWorkbook = ActiveWorkbook
    Cells(1, 1) = "name"
    Cells(1, 2) = "company"
    'Add the rest of the column headings
    N = 1
    For Each Sheet In SourceWorkbook.Sheets
        N = N + 1
        TargetWorkbook.Sheets(1).Cells(N, 1) = Sheet.Cells(7, 4)
        TargetWorkbook.Sheets(1).Cells(N, 2) = Sheet.Cells(1, 1)
        'Add the rest of the source cells
    
    Next Sheet
    
    
    End Sub
    The workbook containing the source data will need to be open.


    Open up the VBA editor by hitting ALT F11

    Insert a new module by hitting Insert - Module

    Paste the macro into the empty sheet

    Hit ALT F11 to get back to the worksheet.

    Run the macro by going to tools-macro in Excel 2003 or the view ribbon in Excel 2007.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0