Attribute VB_Name = "Module2"
Sub Resample_Large_Data_Set()
Attribute Resample_Large_Data_Set.VB_ProcData.VB_Invoke_Func = " \n14"
'This Macro takes the average from every few points to make a x number of data point matrix
' an average based down-sampling
SampleNumber = 1000 'how many data points are needed, this is the output
Cells(1, 1).Activate
counter = 0
counter2 = 0
For n = 1 To 90000 'an auto scaling factor for the number of rows
If Cells(n, 1) > "" Then
counter = counter + 1
End If
Next n
For c = 1 To 200 'an auto scaling factor for the number of columns
If Cells(1, c) > "" Then
counter2 = counter2 + 1
End If
Next c
'Now we calculate the number of divisions to make the total sample output
cuts = WorksheetFunction.Round(counter / SampleNumber, 0)
cutstotal = WorksheetFunction.RoundUp(counter / cuts, 0)
ReDim dataset(counter2, cutstotal + 1)
For t = 1 To counter2
For y = 1 To cutstotal
dataset(t, y) = 0
Next y
Next t
'Load the data and do an average between the values
For c = 1 To counter2
dataset(c, 1) = Cells(1, c)
indexval = 1
For n = 2 To (counter - 1) Step cuts
datam = 0
For cp = 1 To cuts
datam = datam + Cells(n + cp, c)
Next cp
indexval = indexval + 1
dataset(c, indexval) = datam / cuts
Next n
Next c
'Send the data back to a new page
Sheets().Add.Activate
For c = 1 To counter2
For n = 1 To cutstotal
Cells(n, c) = dataset(c, n)
Next n
Next c
End Sub