Hi All,
I have a spreadsheet with 134,000 rows. Each row contains data from a hundredth of a second (1343 seconds total).
Each hundredth of a second has several points of data that was recorded. What I would like to do is, summarize the data by second. (Average & Median of each Data 1, Data 2, Data 3 for each second.)
Example of Data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Time[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[/TR]
[TR]
[TD].001[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD].002[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD].003[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]
I have already set a floor.
Ex:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Time[/TD]
[TD]Floor[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[/TR]
[TR]
[TD].001[/TD]
[TD]0[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD].002[/TD]
[TD]0[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD].003[/TD]
[TD]0[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]6
[/TD]
[/TR]
</tbody>[/TABLE]
Ideally, it would look something like this when done:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Time[/TD]
[TD]Floor[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[TD][/TD]
[TD]Floor[/TD]
[TD]Data 1 Aver.[/TD]
[TD]Data 2 Aver.[/TD]
[TD]Data Three Aver.[/TD]
[/TR]
[TR]
[TD].001[/TD]
[TD]0[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD][/TD]
[TD]0[/TD]
[TD]2.666[/TD]
[TD]3[/TD]
[TD]3.66[/TD]
[/TR]
[TR]
[TD].002[/TD]
[TD]0[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD][/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]3[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD].003[/TD]
[TD]0[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]6
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I've tried writing the following code:
Let me know what you guys think. I am stumped on how to get VBA to take each floor "chunk" and do the calculation. To make things worse, not every second of data contains the same number of datapoints (eg. sometimes there would be multiple seconds repeated) so I can't break the data up every hundred rows.
Thanks for reading!
I have a spreadsheet with 134,000 rows. Each row contains data from a hundredth of a second (1343 seconds total).
Each hundredth of a second has several points of data that was recorded. What I would like to do is, summarize the data by second. (Average & Median of each Data 1, Data 2, Data 3 for each second.)
Example of Data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Time[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[/TR]
[TR]
[TD].001[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD].002[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD].003[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]
I have already set a floor.
Ex:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Time[/TD]
[TD]Floor[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[/TR]
[TR]
[TD].001[/TD]
[TD]0[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD].002[/TD]
[TD]0[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD].003[/TD]
[TD]0[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]6
[/TD]
[/TR]
</tbody>[/TABLE]
Ideally, it would look something like this when done:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Time[/TD]
[TD]Floor[/TD]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[TD]Data 3[/TD]
[TD][/TD]
[TD]Floor[/TD]
[TD]Data 1 Aver.[/TD]
[TD]Data 2 Aver.[/TD]
[TD]Data Three Aver.[/TD]
[/TR]
[TR]
[TD].001[/TD]
[TD]0[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD][/TD]
[TD]0[/TD]
[TD]2.666[/TD]
[TD]3[/TD]
[TD]3.66[/TD]
[/TR]
[TR]
[TD].002[/TD]
[TD]0[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD][/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]3[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD].003[/TD]
[TD]0[/TD]
[TD]5[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]6
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I've tried writing the following code:
Code:
Private Sub cmdRun_Click()
'Declare variables
Dim x As String
Dim row As Integer
Dim lastSecondInFloor
Dim time As String
Dim floor As String
Dim newFloor As String
Dim Data1 As String
Dim Data2 As String
Dim Data3 As String
'Get floor
x = 0
row = 3
floor = Cells(row, 2)
Do
floor = Cells(row, 2)
If floor <> x Then
x = x + 1
'The commented out line below seemed to work for inserting a message into the last line in a "floor"
'I just don't know how to make it take the median/average of whole floor
'Cells(row - 1, 10) = "last"
lastSecondInFloor = row - 1
'This code below didn't work as expected
Cells(row - 1, 10) = WorksheetFunction.Median("lastSecondInFloor,8:row,8")
End If
row = row + 1
'last second number to be found goes here
Loop While x <= 1343
End Sub
Thanks for reading!