#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 191
Default Creating macro

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 834
Default Creating macro

Try

With ActiveCell

.Value2 = "=IF(ISERROR(" & Right$(.Formula, Len(.Formula) - 1) &
"),0," & Right$(.Formula, Len(.Formula) - 1) & ")"
End With


--

HTH

Bob

"Jamie" wrote in message
...
Hi,

Can anyone write a macro for me so that it takes the current formula I
have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 269
Default Creating macro

Use this line of code to change the active cell formula

ActiveCell.Formula = "=if(iserror(" & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & "),0," & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & ")"

This would fix all errors on a the active sheet

Sub FixErrors()
Dim Cell As Object, Sh As Object

For Each Cell In ActiveSheet.UsedRange.Cells
If IsError(Cell.Value) Then
Cell.Formula = "=if(iserror(" & Right(Cell.Formula, Len(Cell.Formula) -
1) & "),0," & Right(Cell.Formula, Len(Cell.Formula) - 1) & ")"
End If
Next Cell

End Sub



--
If this helps, please remember to click yes.


"Jamie" wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Creating macro

Hi,

Try this

r = Mid(Range("c1").Formula, 2)
Range("c1").Formula = "=IF(ISERROR(" & r & "),0," & r & ")"

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Jamie" wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Creating macro

Sub ErrorTrapAdd()
Dim mystr As String
Dim cel As Range
For Each cel In Selection
If cel.HasFormula = True Then
If Not cel.Formula Like "=IF(ISERROR*" Then
mystr = Right(cel.Formula, Len(cel.Formula) - 1)
cel.Value = "=IF(ISERROR(" & mystr & "),0," & mystr & ")"
End If
End If
Next
End Sub


Gord Dibben MS Excel MVP

On Tue, 6 Apr 2010 10:48:04 -0700, Jamie
wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 191
Default Creating macro

I put in the below formula but keep getting a syntax error.

Sub FixErrors()
Dim Cell As Object, Sh As Object

For Each Cell In ActiveSheet.UsedRange.Cells
If IsError(Cell.Value) Then
Cell.Formula = "=if(iserror(" & Right(Cell.Formula, Len(Cell.Formula) -
1) & "),0," & Right(Cell.Formula, Len(Cell.Formula) - 1) & ")"
End If
Next Cell

End Sub


"Paul C" wrote:

Use this line of code to change the active cell formula

ActiveCell.Formula = "=if(iserror(" & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & "),0," & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & ")"

This would fix all errors on a the active sheet

Sub FixErrors()
Dim Cell As Object, Sh As Object

For Each Cell In ActiveSheet.UsedRange.Cells
If IsError(Cell.Value) Then
Cell.Formula = "=if(iserror(" & Right(Cell.Formula, Len(Cell.Formula) -
1) & "),0," & Right(Cell.Formula, Len(Cell.Formula) - 1) & ")"
End If
Next Cell

End Sub



--
If this helps, please remember to click yes.


"Jamie" wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 191
Default Creating macro

I figured out the issue. Is there a way to make that macro only work the
cells selected? That would be more helpful.

Thanks - Jamie

"Paul C" wrote:

Use this line of code to change the active cell formula

ActiveCell.Formula = "=if(iserror(" & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & "),0," & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & ")"

This would fix all errors on a the active sheet

Sub FixErrors()
Dim Cell As Object, Sh As Object

For Each Cell In ActiveSheet.UsedRange.Cells
If IsError(Cell.Value) Then
Cell.Formula = "=if(iserror(" & Right(Cell.Formula, Len(Cell.Formula) -
1) & "),0," & Right(Cell.Formula, Len(Cell.Formula) - 1) & ")"
End If
Next Cell

End Sub



--
If this helps, please remember to click yes.


"Jamie" wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 126
Default Creating macro

Try...
For Each Cell In Selection

--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Jamie" wrote:

I figured out the issue. Is there a way to make that macro only work the
cells selected? That would be more helpful.

Thanks - Jamie

"Paul C" wrote:

Use this line of code to change the active cell formula

ActiveCell.Formula = "=if(iserror(" & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & "),0," & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & ")"

This would fix all errors on a the active sheet

Sub FixErrors()
Dim Cell As Object, Sh As Object

For Each Cell In ActiveSheet.UsedRange.Cells
If IsError(Cell.Value) Then
Cell.Formula = "=if(iserror(" & Right(Cell.Formula, Len(Cell.Formula) -
1) & "),0," & Right(Cell.Formula, Len(Cell.Formula) - 1) & ")"
End If
Next Cell

End Sub



--
If this helps, please remember to click yes.


"Jamie" wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 834
Default Creating macro

For Each cell In Selection

With Cell

. Value2 = "=IF(ISERROR(" & Right$(.Formula, Len(.Formula) - 1) &
_
"),0," & Right$(.Formula, Len(.Formula) - 1) &
")"
End With
Next cell


--

HTH

Bob

"Jamie" wrote in message
...
I figured out the issue. Is there a way to make that macro only work the
cells selected? That would be more helpful.

Thanks - Jamie

"Paul C" wrote:

Use this line of code to change the active cell formula

ActiveCell.Formula = "=if(iserror(" & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & "),0," & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & ")"

This would fix all errors on a the active sheet

Sub FixErrors()
Dim Cell As Object, Sh As Object

For Each Cell In ActiveSheet.UsedRange.Cells
If IsError(Cell.Value) Then
Cell.Formula = "=if(iserror(" & Right(Cell.Formula,
Len(Cell.Formula) -
1) & "),0," & Right(Cell.Formula, Len(Cell.Formula) - 1) & ")"
End If
Next Cell

End Sub



--
If this helps, please remember to click yes.


"Jamie" wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I
have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.



  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Creating macro

See my post.


Gord

On Tue, 6 Apr 2010 11:37:20 -0700, Jamie
wrote:

I figured out the issue. Is there a way to make that macro only work the
cells selected? That would be more helpful.

Thanks - Jamie

"Paul C" wrote:

Use this line of code to change the active cell formula

ActiveCell.Formula = "=if(iserror(" & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & "),0," & Right(ActiveCell.Formula,
Len(ActiveCell.Formula) - 1) & ")"

This would fix all errors on a the active sheet

Sub FixErrors()
Dim Cell As Object, Sh As Object

For Each Cell In ActiveSheet.UsedRange.Cells
If IsError(Cell.Value) Then
Cell.Formula = "=if(iserror(" & Right(Cell.Formula, Len(Cell.Formula) -
1) & "),0," & Right(Cell.Formula, Len(Cell.Formula) - 1) & ")"
End If
Next Cell

End Sub



--
If this helps, please remember to click yes.


"Jamie" wrote:

Hi,

Can anyone write a macro for me so that it takes the current formula I have
in a cell and adds a IF function and iserror fuction around it.

Here is what I would like:

Current formula =A1/B1

after running the macro I would like it to look like this:
=if(iserror(A1/B1),0,A1/B1)

Thanks for your help.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Macro the right way? Hvns Excel Worksheet Functions 2 January 25th 10 09:16 PM
VBA and creating a Macro tommy Excel Discussion (Misc queries) 4 January 28th 09 03:52 PM
Creating a New Macro SharonJo Excel Discussion (Misc queries) 1 April 4th 08 01:27 AM
Creating a macro Gene Goldenfeld New Users to Excel 10 May 5th 05 04:28 PM
Need Help Creating A Macro LJ Owen Excel Worksheet Functions 1 March 2nd 05 01:52 PM


All times are GMT +1. The time now is 07:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"