This fixes the syntax errors. I don't know if it produces the results you expect.
Sub Main()
Dim Rng As Range
Dim p As Long, N As Long
Dim nBase, nPeak, mid As Long
Set Rng = Range("H2:H97")
'form a counter that is as long as The number of days by finding the total entries
N = WorksheetFunction.CountA(Columns(3)) 'n is the total entrys
'Take number of data points (n) and divide by 96 to get number of days
days = N / 96
'and work out the upper and lower limits (2.5 and 97.5 percentiles)
For p = 1 To days
nBase = WorksheetFunction.Percentile(Rng, 0.025)
Sheets("out").Cells(p, "A").Value = nBase
nPeak = WorksheetFunction.Percentile(Rng, 0.975)
Sheets("out").Cells(p, "B").Value = nPeak
mid = nBase + (nPeak - nBase) / 2
Sheets("out").Cells(p, "C").Value = mid
'For the current range (rng) find the first cell in column H which is above mid, return the time
'also find the Cell at which the data drops below the mid, return this time
For Each c In Rng
If c.Value > mid Then
'Cells(p,"D") = The adjacent cell in the E column?
Exit For
End If
'But now I want to keep the loop going and find the time where it crosses below the mid
Next c
Set Rng = Rng.Offset(96, 0) 'use this to cycle through days (relys on 15min data, will update to recognise ranges based on data in future)
Next p
'TODO
'how long is it above this midpoint?
'how long between rise and fall times?
'Reference Testing
'Workbooks("CottonKirkSmallTest").Sheets("data").Range("H2:H97").Font.Bold = False
'Workbooks("CottonKirkSmallTest").Sheets("data").Range("A5:A7").Value = N
'Workbooks("Test").Sheets("Sheet1").Range("A1:D5").Font.Bold = True
End Sub
You were referencing Workbooks("CottonKirkSmall")
The workbook's name is Workbooks("CottonKirkSmall.xlsm")
The workbook reference is not really necessary unless you are switching between workbooks.
You created a loop For Each c In Range(Rng)
Changed to For Each c In Rng
Debugging VBA
Bookmarks