Need Macro to compile data from hundreds of worksheets

JimBobCooter

New Member
Joined
Jan 27, 2017
Messages
6
Hello, I'm new to writing macros and have not been able to make much headway using online instructions or youtube. I have a few hundred excel files, each containing 3 worksheets. I'd like to pull data from a specific worksheet called "Physician Results" and have the data compiled into a single new table. Note, the data that I would like to compile are all the results of formulas calculated, but I just need the values (I would normally copy and paste special -> values for these). The original worksheets contain the data I would like to compile as follows:

In cells O29:P38
10
220
340
460
580
6100
7120
8140
9160
10180

<tbody>
</tbody>

In cells R29:V38
7294.5Yes
164204.1Yes
83114.1Yes
103134.5Yes
154194.4Yes
325374.1Yes
274314.1Yes
295344.3Yes
285334.4Yes
276333.8Yes

<tbody>
</tbody>

In cell F13,
Doe, Jane D

<tbody>
</tbody>

In cell G30,
25

<tbody>
</tbody>

In cell G32,
3

<tbody>
</tbody>

In cell G34,
28

<tbody>
</tbody>

I would like the data compiled into a summary worksheet as follows:
107294.5YesDoe, Jane D25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
220164204.1<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
34083114.1<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
460103134.5<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
580154194.4<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
6100325374.1<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
7120274314.1<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
8140295344.3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
9160285334.4<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28
10180276333.8<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>YesDoe, Jane D<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>25<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>3<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}</style>28

<tbody>
</tbody>

The data from each original worksheet would appear in the row after the data from the first original worksheet so that the result is one summary table with ~2000 rows and 11 columns.

Any help here would be hugely appreciated.
Thanks for your consideration.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Are the files all in one directory? If so, what is the directory path? If not, is there a list of the file names (with file extension) and their respective paths on a sheet that can be referenced? One of these options must be available in order to automate the opening and closing of the files to do the copying. Otherwise, the code would have to be written so the user would manually open and close all the files.
 
Upvote 0
JimBobCooter,

You might consider the following...

Code:
Sub AnotherMaster_1021484()
Application.ScreenUpdating = False
Dim wb As Workbook, wb2 As Workbook
Dim FolderName As String, fileName As String
Dim errLog As String, err As Boolean
Dim arr1() As Variant, arr2() As Variant
Dim c As Long, r As Long, n As Long, kount As Long
Dim rng As Range
Dim value1 As String, Value2 As Long, value3 As Long, value4 As Long

''''Select folder that contains files
With Application.FileDialog(msoFileDialogFolderPicker)
  .AllowMultiSelect = False
  If .Show = 0 Then Exit Sub
  FolderName = .SelectedItems(1) & "\"
End With

Set wb = Workbooks.Add
fileName = Dir(FolderName & "*.xls?")
err = False
kount = 0
n = 10

''''Loop through files
Do While fileName <> ""
    Set wb2 = Workbooks.Open(FolderName & fileName)
        On Error GoTo errHandler
        Set rng = wb2.Sheets("Physician Results").Range("O29:V38")
        value1 = wb2.Sheets("Physician Results").Range("F13")
        Value2 = wb2.Sheets("Physician Results").Range("G30")
        value3 = wb2.Sheets("Physician Results").Range("G32")
        value4 = wb2.Sheets("Physician Results").Range("G34")
        
        ''''Populate arrays
        arr1 = Application.Transpose(rng)
        ReDim Preserve arr2(1 To 12, 1 To n)
        For r = 1 To 8
            For c = 1 To 10
                arr2(r, c + kount) = arr1(r, c)
            Next c
        Next r
        For c = 1 To 10
            arr2(9, c + kount) = value1
            arr2(10, c + kount) = Value2
            arr2(11, c + kount) = value3
            arr2(12, c + kount) = value4
        Next c
        n = n + 10
        kount = kount + 10
Nexxt:
    wb2.Close savechanges:=False
    fileName = Dir
Loop

''''Write array to new workbook
With wb.Sheets(1)
    .Range(Cells(1, 1), Cells(n - 10, 12)) = Application.Transpose(arr2)
    .Columns(3).Delete
    .Columns.AutoFit
End With

Application.ScreenUpdating = True
MsgBox "The dishes are done, dude!"
If err = True Then MsgBox "These files do not have a Physician Results worksheet:" & vbCrLf & vbCrLf & errLog
Exit Sub
errHandler:
    errLog = errLog & wb2.Name & vbCrLf
    err = True
    Resume Nexxt
End Sub

Cheers,

tonyyy
 
Upvote 0
Thanks, JLGWhiz, yes, the files will all be in one directory. The directory path is: /Users/JameelShah 1/Documents/Center for SIBO Testing/CFST Laboratory/BreathTracker Results.

Thanks for your help here.
 
Upvote 0

Forum statistics

Threads
1,215,631
Messages
6,125,905
Members
449,273
Latest member
mrcsbenson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top