Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Tang123
 
Posts: n/a
Default Macro to edit formula


I have a formula which gives a #n/a in the cell :
=VLOOKUP(A1,B14:C29,2,FALSE)

In order not to show #n/a, I've edited the cell and changed it to:
=IF(ISERROR(VLOOKUP(A1,B14:C29,2,FALSE)),0,VLOOKUP (A1,B14:C29,2,FALSE))

Is there a way to create a macro so that I don't have to edit the
formula every time. In other words, the macro will do all the editing
for me.

Thanks in advance for your help!


--
Tang123
------------------------------------------------------------------------
Tang123's Profile: http://www.excelforum.com/member.php...o&userid=27846
View this thread: http://www.excelforum.com/showthread...hreadid=473577

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

One way...

Option Explicit
Sub testme()

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
With myCell
myStr = Mid(.Formula, 2)
myStr = "=if(iserror(" & myStr & "),""""," & myStr & ")"
.Formula = myStr
End With
Next myCell

End Sub

Select your range of cells to fix and then run this macro.

Tang123 wrote:

I have a formula which gives a #n/a in the cell :
=VLOOKUP(A1,B14:C29,2,FALSE)

In order not to show #n/a, I've edited the cell and changed it to:
=IF(ISERROR(VLOOKUP(A1,B14:C29,2,FALSE)),0,VLOOKUP (A1,B14:C29,2,FALSE))

Is there a way to create a macro so that I don't have to edit the
formula every time. In other words, the macro will do all the editing
for me.

Thanks in advance for your help!

--
Tang123
------------------------------------------------------------------------
Tang123's Profile: http://www.excelforum.com/member.php...o&userid=27846
View this thread: http://www.excelforum.com/showthread...hreadid=473577


--

Dave Peterson
  #3   Report Post  
Tang123
 
Posts: n/a
Default


Thanks Dave.
It works! :)
Much appreciated.


--
Tang123
------------------------------------------------------------------------
Tang123's Profile: http://www.excelforum.com/member.php...o&userid=27846
View this thread: http://www.excelforum.com/showthread...hreadid=473577

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
i edit a formula (excel) then it displays formula not answer caiman Excel Discussion (Misc queries) 2 September 9th 05 02:09 AM
Cannat paste that macro formula onto a worksheet Stephen White Excel Discussion (Misc queries) 2 May 27th 05 11:58 AM
Can I start a macro from a cell by using a formula PraxisPete Excel Worksheet Functions 1 April 8th 05 08:57 AM
Formula linked to cell with Macro Beginner Excel Worksheet Functions 0 March 30th 05 10:51 PM
Can you enter a formula in a cell to run a macro? Nevaeh Excel Worksheet Functions 2 February 14th 05 11:51 PM


All times are GMT +1. The time now is 12:58 PM.

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

About Us

"It's about Microsoft Excel"