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?
Thanks!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
Last edited by Uziel; 03-17-2010 at 05:11 PM. Reason: shg told me to :)
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
Hi,
A UDF will slow you down a touch. How about
=SUMPRODUCT((ISERROR(range))*1)
Sarcasm - because beating the **** out of someone is illegal.
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?
I think you ought to read my last post.Thoughts?
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Sorry shg, I did not even see your post. I will do that right now.
Your title was fine. What I asked is that you add CODE tags.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
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
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.![]()
Did you read the part about marking threads as Solved?
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks