Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Changing cell formula in VBA

Hi to all !!


I have a small problem in Excel97, although I don't know if the Excel
version is relevant.

In some of my sheets, I've elaborated some complex formulas which,
sometimes, can lead to
the infamous "#NA" result.

I want to replace the "#NA" by a clean 2 characters "NA" string.

As there are MANY formulas, I want to develop a VBA sub which does the work :

a) pick up the actual formula (which we'll define as FormulaContent)
(maybe save the activecell.address so as to be able to write to
that range)

b) replace it by
IF(ISERROR( FC ),"NA", FC)

WHERE FC is FormulaContent without the preceeding "=" sign


I thank you by advance.
Best regards,

--
Herve Hanuise
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Changing cell formula in VBA

Hi Herve

you could try something like this

Sub Exchange_Formula()

Dim cell_ As Range

Dim str_formula As String
For Each cell_ In ActiveSheet.Cells
If cell_.HasFormula Then
str_formula = Right(cell_.Formula, Len(cell_.Formula) - 1)
cell_.Formula = "=if(iserror(" & str_formula & "),""NA""," &
str_formula & ")"
End If
Next cell_

End Sub


hth

Carlo

On Nov 29, 3:24 pm, affordsol
wrote:
Hi to all !!

I have a small problem in Excel97, although I don't know if the Excel
version is relevant.

In some of my sheets, I've elaborated some complex formulas which,
sometimes, can lead to
the infamous "#NA" result.

I want to replace the "#NA" by a clean 2 characters "NA" string.

As there are MANY formulas, I want to develop a VBA sub which does the work :

a) pick up the actual formula (which we'll define as FormulaContent)
(maybe save the activecell.address so as to be able to write to
that range)

b) replace it by
IF(ISERROR( FC ),"NA", FC)

WHERE FC is FormulaContent without the preceeding "=" sign

I thank you by advance.
Best regards,

--
Herve Hanuise


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Changing cell formula in VBA

Hi Carlo !


So sorry for the late reply but I wish to thank you for your code : it does
the job quite perfectly.

I just changed it a little bit to match MY OWN ranges and I post it here so
as to 'empower' anyone which might be interested in the post.

Best regards from Belgium,
Hervé+

'================================================= ==============
Sub VoidNAinPrintout()
Dim cell_ As Range
Dim str_formula As String
'Here is the all sheet startup
'For Each cell_ In ActiveSheet.Cells
For Each cell_ In ActiveSheet.Range("L25:P26")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J31:U33")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J35:U39")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J41:U44")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J49:U61")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J63:U70")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J75:U77")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J79:U98")
GoSub CLEANME
Next cell_
For Each cell_ In ActiveSheet.Range("J102:U104")
GoSub CLEANME
Next cell_
Exit Sub
'<<<<<<<<<<<<<<<<<<<
CLEANME:
If cell_.HasFormula Then
str_formula = Right(cell_.Formula, Len(cell_.Formula) - 1)
cell_.Formula = "=if(iserror(" & str_formula & "),""NA""," & str_formula
& ")"
End If
Return
'
End Sub
'================================================= ==============

--
Herve Hanuise


"carlo" wrote:

Hi Herve

you could try something like this

Sub Exchange_Formula()

Dim cell_ As Range

Dim str_formula As String
For Each cell_ In ActiveSheet.Cells
If cell_.HasFormula Then
str_formula = Right(cell_.Formula, Len(cell_.Formula) - 1)
cell_.Formula = "=if(iserror(" & str_formula & "),""NA""," &
str_formula & ")"
End If
Next cell_

End Sub


hth

Carlo

On Nov 29, 3:24 pm, affordsol
wrote:
Hi to all !!

I have a small problem in Excel97, although I don't know if the Excel
version is relevant.

In some of my sheets, I've elaborated some complex formulas which,
sometimes, can lead to
the infamous "#NA" result.

I want to replace the "#NA" by a clean 2 characters "NA" string.

As there are MANY formulas, I want to develop a VBA sub which does the work :

a) pick up the actual formula (which we'll define as FormulaContent)
(maybe save the activecell.address so as to be able to write to
that range)

b) replace it by
IF(ISERROR( FC ),"NA", FC)

WHERE FC is FormulaContent without the preceeding "=" sign

I thank you by advance.
Best regards,

--
Herve Hanuise



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
HELP...Draging cell without changing Formula linked to cell Wilco Excel Discussion (Misc queries) 4 February 5th 11 10:44 AM
changing cell formula specialc Excel Worksheet Functions 1 March 30th 09 06:59 PM
how to edit formula without changing formula of each cell sadat Excel Worksheet Functions 2 April 24th 07 02:02 PM
get the value of a formula in cell B1 into cell A1 without changing my current cell selection News[_4_] Excel Programming 3 October 21st 06 12:24 AM
Changing cell from formula to data. TimM Excel Discussion (Misc queries) 2 January 6th 06 08:35 PM


All times are GMT +1. The time now is 02:39 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"