Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Auto IsError

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WBTKbeezy - 21 Nov 2007 14:42 GMT
Hello:

I found this code online from Microsoft that automatically changes a formula
to an ISERROR formula using your original formula...

http://support.microsoft.com/kb/213387

It works awesome, but it only does one cell at a time. I have been trying,
with little success, to make it work so I can select a section and it will
work through the whole thing. Can anyone provide assistance?
Dave Peterson - 21 Nov 2007 15:34 GMT
This is the suggested code:

Sub ErrorToZero()
   X = Right(ActiveCell.Formula,Len(ActiveCell.Formula)-1)
   ActiveCell.Formula = "=IF(ISERROR(" & X & "),0," & X & ")"
End Sub

I'd use:

Option Explicit
Sub ErrorToZero2()
   Dim myRng As Range
   Dim myCell As Range
   Dim myStr As String
   
   Set myRng = Nothing
   On Error Resume Next
   Set myRng = Intersect(Selection, _
                     Selection.Cells.SpecialCells(xlCellTypeFormulas))
   On Error GoTo 0
   
   If myRng Is Nothing Then
       MsgBox "No formulas in selection!"
       Exit Sub
   End If
   
   For Each myCell In myRng.Cells
       myStr = Mid(myCell.Formula, 2)
       myCell.Formula = "=If(iserror(" & myStr & "),0," & myStr & ")"
   Next myCell
   
End Sub

> Hello:
>
[quoted text clipped - 6 lines]
> with little success, to make it work so I can select a section and it will
> work through the whole thing. Can anyone provide assistance?

Signature

Dave Peterson

WBTKbeezy - 21 Nov 2007 16:07 GMT
That is perfect, Dave, Thanks!

The Error Handler is a nice touch as well.

> This is the suggested code:
>
[quoted text clipped - 39 lines]
> > with little success, to make it work so I can select a section and it will
> > work through the whole thing. Can anyone provide assistance?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.