Sub Gather_Data()
'
' Formats data if necessary
If InStr(Worksheets("Data 1 sec").Cells(1, 1), ",") Then
Worksheets("Data 1 sec").Select
Columns("A:A").Select
Application.DisplayAlerts = False
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, Comma:=True
Application.DisplayAlerts = True
Cells(1, 1).Select
End If
If InStr(Worksheets("Data 30 secs").Cells(1, 1), ",") Then
Worksheets("Data 30 secs").Select
Columns("A:A").Select
Application.DisplayAlerts = False
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, Comma:=True
Application.DisplayAlerts = True
Cells(1, 1).Select
End If
' Cleans unused data if not done before
If (Worksheets("Data 1 sec").Cells(2, 2).Value) < TimeValue("07:39:59") Then
Worksheets("Data 1 sec").Rows("2:6000").Delete
Worksheets("Data 1 sec").Rows("32002:51000").Delete
Worksheets("Data 1 sec").Range("A3:A33000").ClearContents
Worksheets("Data 30 secs").Range("A3:A1564").ClearContents
End If
' Writes times every 30 seconds to the "1 sec work" worksheet
For j = 3 To 32000
If Round((j - 4) / 30, 0) = (j - 4) / 30 Then Worksheets("1 sec work").Cells(j, 3).Value = Worksheets("Data 1 sec").Cells(j - 1, 2).Value
Next
' Calculates the "1 sec work" worksheet
For i = 3 To Worksheets("Data 1 sec").Cells(1, Columns.Count).End(xlToLeft).Column - 1
'Writes log
Call Write_Log("Gathering data : doing server #" & i - 2)
Worksheets("1 sec work").Cells(1, ((i - 2) * 2) + 2).Value = Mid(Worksheets("Data 1 sec").Cells(1, i).Value, 6)
Worksheets("1 sec work").Cells(2, ((i - 2) * 2) + 2).Value = "= ""> "" & $B$4"
Worksheets("1 sec work").Cells(2, ((i - 2) * 2) + 3).Value = "= ""> "" & $B$5"
For j = 3 To 32000
' Writes log
If Round(j / 5000, 0) = j / 5000 Then Call Write_Log("Calculated " & j & " entries for server #" & i - 2)
' If value of current cell from Data 1 sec is greater than threshold T2
If Worksheets("Data 1 sec").Cells(j - 2, i).Value > Worksheets("1 sec work").Range("B4") Then
' Increments value from previous cell if this is not the first line
If j > 3 Then
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 2).Value = Worksheets("1 sec work").Cells(j - 1, ((i - 2) * 2) + 2).Value + 1
Else
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 2).Value = 1
End If
Else
' If this is not the second line and if value of current cells from Data 1 sec is NOT greater than threshold BUT the previous one is
If j > 4 And Worksheets("Data 1 sec").Cells(j - 3, i).Value > Worksheets("1 sec work").Range("B4") Then
' Copies value from previous cell
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 2).Value = Worksheets("1 sec work").Cells(j - 1, ((i - 2) * 2) + 2).Value
Else
' Resets last and current values to nothing
If j > 3 Then Worksheets("1 sec work").Cells(j - 1, ((i - 2) * 2) + 2).Value = ""
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 2).Value = ""
End If
End If
' If value of current cell from Data 1 sec is greater than threshold T3
If Worksheets("Data 1 sec").Cells(j - 2, i).Value > Worksheets("1 sec work").Range("B5") Then
' Increments value from previous cell
If j > 3 Then
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 3).Value = Worksheets("1 sec work").Cells(j - 1, ((i - 2) * 2) + 3).Value + 1
Else
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 3).Value = 1
End If
Else
' If this is not the second line and if value of current cells from Data 1 sec is NOT greater than threshold BUT the previous one is
If j > 4 And Worksheets("Data 1 sec").Cells(j - 3, i).Value > Worksheets("1 sec work").Range("B5") Then
' Copies value from previous cell
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 3).Value = Worksheets("1 sec work").Cells(j - 1, ((i - 2) * 2) + 3).Value
Else
' Restes value to nothing
If j > 3 Then Worksheets("1 sec work").Cells(j - 1, ((i - 2) * 2) + 3).Value = ""
Worksheets("1 sec work").Cells(j, ((i - 2) * 2) + 3).Value = ""
End If
End If
Next
Next
Call Write_Log("Done gathering data")
End Sub
You will note there are a few
Bookmarks