Not really clear.
Sub test()
Dim myDir As String, fn As String, n As Long, wsName As String, FileName As String, x
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then myDir = .SelectedItems(1) & "\"
End With
If myDir = "" Then Exit Sub
fn = Dir(myDir & "*.xls")
If fn = "" Then Exit Sub
With Sheets(1)
.Cells(1).CurrentRegion.ClearContents: n = 1
.Cells(1).Resize(, 5).Value = Array("BORE_ID", "Max", "Date", "Min", "Date")
Do While fn <> ""
n = n + 1: wsName = Left$(fn, InStrRev(fn, ".") - 1)
FileName = "'" & myDir & "[" & fn & "]" & wsName & "'!"
.Cells(n, 1).Value = wsName
.Cells(n, 2).Value = ExecuteExcel4Macro("max(" & FileName & "c5:c5)")
.Cells(n, 3).Value = ExecuteExcel4Macro("index(" & FileName & _
"c2:c2,match(" & .Cells(n, 2).Value & "," & FileName & "c5:c5,0),)")
.Cells(n, 4).Value = ExecuteExcel4Macro("min(" & FileName & "c5:c5)")
.Cells(n, 5).Value = ExecuteExcel4Macro("index(" & FileName & _
"c2:c2,match(" & .Cells(n, 4).Value & "," & FileName & "c5:c5,0),)")
With .Cells(n, 7).Resize(, 20)
.Formula = "=if(" & FileName & "a2<>""""," & FileName & "a2,"""")"
.Value = .Value
End With
n = n + 1
x = ExecuteExcel4Macro("counta(" & FileName & "c1:c1)")
With .Cells(n, 7).Resize(, 20)
.Formula = "=if(" & FileName & "a" & x & "<>""""," & FileName & "a" & x & ","""")"
.Value = .Value
End With
fn = Dir
Loop
.Range("c:c,e:e").NumberFormat = "yyyy/m/d"
End With
End Sub
Bookmarks