Option Explicit
Sub GetMyData()
' hiker95, 06/23/2010
Dim myDir As String, fn As String, sn As String
Dim NC As Long, CName As String
Application.ScreenUpdating = False
'myDir = "C:\TestData" 'for testing
myDir = "C:\Documents and Settings\Michael\My Documents\Inclusion Research\Expense\2008"
sn = "Sheet1"
fn = Dir(myDir & "\*.xlsx")
With ThisWorkbook.Sheets("Sheet3")
NC = .Cells(2, Columns.Count).End(xlToLeft).Column + 1
CName = Replace(Cells(1, NC).Address(0, 0), 1, "")
.Columns("B:" & CName).Delete
End With
Do While fn <> ""
If fn <> ThisWorkbook.Name Then
With ThisWorkbook.Sheets("Sheet3")
NC = .Cells(1, Columns.Count).End(xlToLeft).Column + 1
If NC = 1 Then NC = 2
With .Cells(1, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!B1"
.Value = .Value
.NumberFormat = "d-mmm-yy"
End With
With .Cells(2, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I14"
.Value = .Value
End With
With .Cells(3, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I15"
.Value = .Value
End With
With .Cells(4, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I16"
.Value = .Value
End With
With .Cells(5, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I17"
.Value = .Value
End With
With .Cells(6, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I18"
.Value = .Value
End With
With .Cells(7, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I19"
.Value = .Value
End With
With .Cells(8, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I20"
.Value = .Value
End With
With .Cells(9, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I21"
.Value = .Value
End With
With .Cells(10, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I22"
.Value = .Value
End With
With .Cells(11, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I23"
.Value = .Value
End With
With .Cells(12, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I24"
.Value = .Value
End With
With .Cells(13, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I25"
.Value = .Value
End With
With .Cells(14, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I26"
.Value = .Value
End With
With .Cells(15, NC)
.Formula = "='" & myDir & "\[" & fn & "]" & sn & "'!I27"
.Value = .Value
End With
.Range(.Cells(2, NC), .Cells(15, NC)).NumberFormat = "#,##0.00"
.Range(.Cells(1, NC), .Cells(15, NC)).Columns.AutoFit
End With
End If
fn = Dir
Loop
With ThisWorkbook.Sheets("Sheet3")
NC = .Cells(1, Columns.Count).End(xlToLeft).Column + 1
With .Cells(1, NC)
.Value = "TOTALS"
.Font.Bold = True
.HorizontalAlignment = xlCenter
.Font.Name = "Arial"
.Font.Size = 10
.Font.Underline = xlUnderlineStyleSingle
End With
With .Cells(16, NC - 1)
.Value = "TOTAL EXPENSES:"
.Font.Name = "Arial"
.Font.FontStyle = "Bold"
.Font.Size = 10
.HorizontalAlignment = xlRight
End With
CName = Replace(Cells(1, NC - 1).Address(0, 0), 1, "")
.Cells(2, NC).Formula = "=SUM(B2:" & CName & "2)"
.Cells(2, NC).Copy .Cells(3, NC).Resize(13)
CName = Replace(Cells(1, NC).Address(0, 0), 1, "")
.Cells(16, NC).Formula = "=SUM(" & CName & "2:" & CName & "15)"
With .Range(CName & "2:" & CName & "16")
.NumberFormat = "$#,##0.00"
.Font.Name = "Arial"
.Font.FontStyle = "Bold"
.Font.Size = 10
End With
.Range(CName & "1:" & CName & "16").Columns.AutoFit
End With
Application.ScreenUpdating = True
End Sub