+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    11-09-2007
    Posts
    38

    Question Trying to find a formula that QUICKLY counts errors, formula or results, on a SS

    I am trying to just count errors in a defind range on my spreadsheet. I tried using an array formula but it killed the processing time. I then tried a UDF, shown below, but it also kills the processing time because it runs more than once when doing a standard calculation. Is there a way to set the formula to only run at the end of a calc cycle?

    Code:
    Function CountErrors()
    Dim rng, c As Range, e As Integer
    
    Set rng = ActiveSheet.UsedRange
        For Each c In rng
            If InStr(1, c.Formula, "#REF!") Or IsError(c) Then
                CountErrors = CountErrors + 1
            End If
        Next c
    End Function
    Thanks!
    Last edited by Uziel; 03-17-2010 at 05:11 PM. Reason: shg told me to :)

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,138

    Re: Counting Errors

    Please take a few minutes to read the forum rules, and then edit your post to add CODE tags.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru sweep's Avatar
    Join Date
    04-03-2007
    Location
    Location: Location:
    MS-Off Ver
    XL2003 / 2007
    Posts
    2,448

    Re: Counting Errors

    Hi,

    A UDF will slow you down a touch. How about

    =SUMPRODUCT((ISERROR(range))*1)
    Sarcasm - because beating the **** out of someone is illegal.

  4. #4
    Registered User
    Join Date
    11-09-2007
    Posts
    38

    Re: Counting Errors

    I think that formula has the same problem as the UDF. It takes 2.5 seconds to calculate without the formula. I added the formula, hit calculate, and stopped the calculation when it was at 30% done and 30 seconds into the calculation.... Excel seems to repeatedly calculate both formulas where it only needs to be done once...at the end.

    Thoughts?

  5. #5
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,138

    Re: Counting Errors

    Thoughts?
    I think you ought to read my last post.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    11-09-2007
    Posts
    38

    Re: Counting Errors

    Sorry shg, I did not even see your post. I will do that right now.

  7. #7
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,138

    Re: Trying to find a formula that QUICKLY counts errors, formula or results, on a SS

    Your title was fine. What I asked is that you add CODE tags.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,138

    Re: Trying to find a formula that QUICKLY counts errors, formula or results, on a SS

    Third time's the charm.

    Try this; code goes in the Sheet module:
    Code:
    Private Sub Worksheet_Calculate()
        Dim nErr As Long
        
        On Error Resume Next
        nErr = Me.UsedRange.SpecialCells(xlCellTypeFormulas, xlErrors).Count
        
        Application.EnableEvents = False
        Range("A1").Value = "Errors: " & nErr   ' change range as desired
        Application.EnableEvents = True
    End Sub
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    11-09-2007
    Posts
    38

    Re: Trying to find a formula that QUICKLY counts errors, formula or results, on a SS

    Thank you sir. Just off that one bit of code a learned a NUMBER of new things!

    I apologize about the trouble with the post. I am now officially trained.

  10. #10
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,138

    Re: Trying to find a formula that QUICKLY counts errors, formula or results, on a SS

    Did you read the part about marking threads as Solved?
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0