I'm curious....How are you performing this code if you have already closed the file...Workbooks(FileItem.Name)
ActiveSheet.Cells(FileNumber, 5) = Logavg
ActiveSheet.Cells(FileNumber, 6) = Max
ActiveSheet.Cells(FileNumber, 3) = "1"
ActiveSheet.Cells(FileNumber, 9) = (Hour(Workbooks(FileItem.Name).Sheets(1).Cells(LastRow, 3))) - (Hour(Workbooks(FileItem.Name).Sheets(1).Cells(2, 3)))
ActiveSheet.Cells(FileNumber, 1) = Workbooks(FileItem.Name).Sheets(1).Cells(2, 2)
What is the reason for this...
Added = 0
Added = Added + Workbooks(FileItem.Name).Sheets(1).Cells(r, 12)
Have a look at amended code...Might just be a shot in the dark...
Private Sub CommandButton1_Click()
Dim FSO As Object, SourceFolder As Object, FileItem As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(ThisWorkbook.Path)
Dim LastRow As Long, Sum As Long, FileNumber As Long
Dim Min As Double, Max As Double, StDev As Double, Logavg As Double, Hr As Double, val As Double
Application.ScreenUpdating = False
With ActiveSheet
.Cells(1, 5) = "Logger Avg."
.Cells(1, 6) = "Logger Max."
.Cells(1, 7) = "Logger Min."
.Cells(1, 8) = "Std. Dev."
End With
FileNumber = 18
For Each FileItem In SourceFolder.Files
If FileItem.Name <> ThisWorkbook.Name Then
Workbooks.Open (ThisWorkbook.Path & Application.PathSeparator & FileItem.Name)
With ActiveSheet
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To LastRow
If .Cells(r, 4) <= 90 Then
.Cells(r, 12) = 10 ^ .Cells(r, 4) / 10
Summ = Summ + .Cells(r, 12)
End If
Next r
N = Summ / (LastRow - 1)
Logavg = 10 * Log10(N)
Max = Application.WorksheetFunction.Max(.Range(Cells(2, 4), .Cells(LastRow, 4)).Value)
Min = Application.WorksheetFunction.Min(.Range(Cells(2, 4), .Cells(LastRow, 4)).Value)
StDev = Application.WorksheetFunction.StDev(.Range(Cells(2, 4), .Cells(LastRow, 4)).Value)
Hr = (Hour(.Cells(LastRow, 3))) - (Hour(.Cells(2, 3)))
val = .Cells(2, 2)
End With
End If
Workbooks(FileItem.Name).Save
Workbooks(FileItem.Name).Close
FileNumber = FileNumber + 1
With ActiveSheet
.Cells(FileNumber, 5) = Logavg
.Cells(FileNumber, 6) = Max
.Cells(FileNumber, 3) = "1"
.Cells(FileNumber, 9) = Hr
.Cells(FileNumber, 1) = val
End With
Next FileItem
Application.ScreenUpdating = True
End Sub
So difficult not actually knowing what you are trying to achieve...it will be alot easier if we knew exactly step by step what you wanted to do...Also with such a huge amount of data..perhaps autofilter would be a better option.
Perhaps someone else can assist further...
Bookmarks