try this:
Option Explicit
Private Sub CommandButton1_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) = "txt" 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 "Count = 0": Exit Sub
avg = sum / count
MsgBox "Sum = " & sum & vbLf & _
"Count = " & count & vbLf & _
"Avg = " & avg & vbLf & _
"Min = " & min & vbLf & _
"Max = " & max
End Sub
Bookmarks