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!
Try this macro
The workbook containing the source data will need to be open.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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks