View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Counting exception number and pop up in MSG BOX

Slightly different code that accomodates all types of errors not just #N/A.
Also a little more generic in that it accommodates changinf number of rows in
the column.

Also when lines turn red it is usually due to the line breaking in the post.
Just edit and bring it all up on to one line. I usually insert line breaks to
prevent this occurring.

A space and an underscore at the end of a line is a line break in an
otherwise single line of code.

Sub MsgBoxReport()

Dim lngOK As Long
Dim lngFail As Long
Dim lngErrors As Long
Dim rngOK_Fail As Range
Dim c As Range

With Sheets("Sheet1")
'Edit "B" (twice) in folowing to your required column
Set rngOK_Fail = .Range(.Cells(2, "B"), _
.Cells(.Rows.Count, "B").End(xlUp))
End With

lngOK = WorksheetFunction.CountIf(rngOK_Fail, "OK")

lngFail = WorksheetFunction.CountIf(rngOK_Fail, "Fail")

For Each c In rngOK_Fail
If IsError(c.Value) Then
lngErrors = lngErrors + 1
End If
Next c

MsgBox "OK = " & lngOK & vbCrLf & _
"Fail = " & lngFail & vbCrLf & _
"Errors = " & lngErrors


End Sub

--
Regards,

OssieMac