Why would I be getting an error with my code?
Private Sub cmdSubmit_Click()
Dim ctrl As Control
Dim sum As Long, avg As Double, count As Long, min As Long, max As Long
min = 2147483647
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" And Left(ctrl.Name, 3) = "cfs" Then
If IsNumeric(ctrl.Value) Then
If ctrl.Value > 0 Then
count = count + 1
sum = sum + ctrl.Value
If max < ctrl.Value Then max = ctrl.Value
If min > ctrl.Value Then min = ctrl.Value
End If
End If
End If
Next ctrl
If count = 0 Then MsgBox "There was no river flow entered. Please check the Wastewater Effluent Report and try again.": Exit Sub
avg = sum / count
MsgBox "Flow Hours = " & count & vbLf & _
"Average River Flow = " & avg & vbLf & _
"Minimal River Flow = " & min
With ThisWorkbook.Worksheets("collection")
lRow = ws.Cells(33, 3).End(xlUp).Row + 1
With ws
.Cells(lRow, "AR").Value = avg
.Cells(lRow, "AS").Value = min
.Cells(lRow, "AT").Value = count
.Cells(lRow, "AU").Value = Me.txtTotalizer.Value
ClearAll
End With
End With
End Sub
Bookmarks