Hello everyone! I am trying to run a macro that calculates some summary statistics on flooding data. Sometimes it works beautifully, and sometimes it returns a runtime error. The only pattern I can see is that it tends to happen when the area is >50% flooded, though not always. I've attached 1 working and 1 non-working data set. I have no idea why this error comes up. Any help would be much appreciated! Macro code is as follows (input row/column may need to be adjusted for each data set):
Sub WaterLevelMacro()
' Set RangeToIncrement = Selection
outputrow = 15
outputColumn = 12
Row = 13
Column = 6
Endrow = 2885
Do Until Row = Endrow
If Cells(Row, Column).Value > 0 Then
Do Until Cells(Row, Column).Value <= 0
Count = Count + 1
Sum = Sum + Cells(Row, Column).Value
Cells(outputrow, outputColumn).Formula = Count * 15
Cells(outputrow, outputColumn + 1).Formula = Sum / Count
Cells(outputrow, outputColumn + 2).Value = Cells(Row, 1).Value
Row = Row + 1
Loop
outputrow = outputrow + 1
Else
Row = Row + 1
Count = 0
Sum = 0
End If
Loop
Beep
End Sub
Bookmarks