PC Review


Reply
Thread Tools Rate Thread

Creating macro

 
 
Jamie
Guest
Posts: n/a
 
      6th Apr 2010
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 With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      6th Apr 2010
Try

With ActiveCell

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


--

HTH

Bob

"Jamie" <(E-Mail Removed)> wrote in message
news:36CDC944-7118-40C5-8473-(E-Mail Removed)...
> 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 With Quote
 
Paul C
Guest
Posts: n/a
 
      6th Apr 2010
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 With Quote
 
Mike H
Guest
Posts: n/a
 
      6th Apr 2010
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.

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      6th Apr 2010
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 <(E-Mail Removed)>
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 With Quote
 
Jamie
Guest
Posts: n/a
 
      6th Apr 2010
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.

 
Reply With Quote
 
Jamie
Guest
Posts: n/a
 
      6th Apr 2010
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 With Quote
 
Gary Brown
Guest
Posts: n/a
 
      6th Apr 2010
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.

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      6th Apr 2010
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" <(E-Mail Removed)> wrote in message
news:F303E50E-C62D-49E4-845E-(E-Mail Removed)...
>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 With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      6th Apr 2010
See my post.


Gord

On Tue, 6 Apr 2010 11:37:20 -0700, Jamie <(E-Mail Removed)>
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Macro & Macro Button Lady Success Microsoft Excel Worksheet Functions 0 7th May 2009 03:55 PM
Help with creating a Macro Liz J Microsoft Excel Misc 6 2nd Nov 2008 09:34 PM
Creating a macro which presses a button containing a recorded macro petros89 Microsoft Excel Programming 3 5th Oct 2005 02:49 PM
Creating a macro =?Utf-8?B?cGF1bE0=?= Microsoft Excel Programming 2 17th Apr 2005 10:42 PM
Need Help Creating A Macro =?Utf-8?B?TEogT3dlbg==?= Microsoft Excel Worksheet Functions 1 2nd Mar 2005 01:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:17 AM.