Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Len Len is offline
external usenet poster
 
Posts: 162
Default Error Cell "#N/A"

Hi,

How to set VB code to search the entire active worksheet 1 for error
cell “ #N/A “ and replace one or more error cells “ #N/A” with value
cell “ 0.00 ” ?


Please help, thanks

Regards
Len
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Error Cell "#N/A"

For Each cell In Activesheet.UsedRange

If cell.text="#N/A" Then

cell.Value = 0
cell.NumberFormat = "0.00"
End If
Next cell

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Len" wrote in message
...
Hi,

How to set VB code to search the entire active worksheet 1 for error
cell “ #N/A “ and replace one or more error cells “ #N/A” with value
cell “ 0.00 ” ?


Please help, thanks

Regards
Len


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Error Cell "#N/A"

On May 19, 10:59*am, Len wrote:
Hi,

How to set VB code to search the entire active worksheet 1 for error
cell “ #N/A “ and replace one or more error cells “ #N/A” with value
cell *“ 0.00 ” ?

Please help, thanks

Regards
Len


I'm assuming that you are looking for cells containing formulas that
are producing the #N/A, correct? If so, something like this will loop
through all of the cells in the worksheet that contain errors and, if
the error is of the #N/A type, will change their values to "0.00".
This will skip all other errors such as #NAME! and #REF.

Sub sample()
Dim r As Range
For Each r In Cells.SpecialCells(xlCellTypeFormulas, xlErrors)
If Application.WorksheetFunction.IsNA(r) Then _
r.Value = "0.00"
Next r
End Sub

Of course, the best solution would be to have your formula not produce
an error. You could do something like this:
=IF(ISNA(VLOOKUP(......)),"0.00",.....)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error Cell "#N/A"

How to set VB code to search the entire active worksheet 1 for error
cell “ #N/A “ and replace one or more error cells “ #N/A” with value
cell “ 0.00 ” ?


I'm assuming that you are looking for cells containing formulas that
are producing the #N/A, correct? If so, something like this will loop
through all of the cells in the worksheet that contain errors and, if
the error is of the #N/A type, will change their values to "0.00".
This will skip all other errors such as #NAME! and #REF.

Sub sample()
Dim r As Range
For Each r In Cells.SpecialCells(xlCellTypeFormulas, xlErrors)
If Application.WorksheetFunction.IsNA(r) Then _
r.Value = "0.00"
Next r
End Sub


It looks like you might be able to do that without the loop...

Dim R As Range
On Error Resume Next
Set R = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las, xlErrors)
On Error GoTo 0
If Not R Is Nothing Then
R.Value = 0
R.NumberFormat = "0.00"
End If

Rick

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error Cell "#N/A"

It looks like you might be able to do that without the loop...

Dim R As Range
On Error Resume Next
Set R = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las, xlErrors)
On Error GoTo 0
If Not R Is Nothing Then
R.Value = 0
R.NumberFormat = "0.00"
End If


Ignore this code... it will change ALL error cells to 0.00, not just #N/A
errors.

Rick



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Error Cell "#N/A"

On May 19, 11:54Â*am, "Rick Rothstein \(MVP - VB\)"
wrote:
How to set VB code to search the entire active worksheet 1 for error
cell � #N/A � and replace one or more error cells � #N/A� with value
cell � 0.00 � ?


I'm assuming that you are looking for cells containing formulas that
are producing the #N/A, correct? Â*If so, something like this will loop
through all of the cells in the worksheet that contain errors and, if
the error is of the #N/A type, will change their values to "0.00".
This will skip all other errors such as #NAME! and #REF.


Sub sample()
Â* Â* Dim r As Range
Â* Â* For Each r In Cells.SpecialCells(xlCellTypeFormulas, xlErrors)
Â* Â* Â* Â* If Application.WorksheetFunction.IsNA(r) Then _
Â* Â* Â* Â* Â* Â* r.Value = "0.00"
Â* Â* Next r
End Sub


It looks like you might be able to do that without the loop...

Dim R As Range
On Error Resume Next
Set R = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormu las, xlErrors)
On Error GoTo 0
If Not R Is Nothing Then
Â* R.Value = 0
Â* R.NumberFormat = "0.00"
End If

Rick- Hide quoted text -

- Show quoted text -


Rick, that is the way I was going to suggest doing it as well, but he
mentioned that this was only for the #N/As, so I was assuming that he
could possibly have other errors in the sheet. Without the loop, it
would change all of the errors to 0.00, not just the #N/As.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error Cell "#N/A"

Rick, that is the way I was going to suggest doing it as well, but he
mentioned that this was only for the #N/As, so I was assuming that he
could possibly have other errors in the sheet. Without the loop, it
would change all of the errors to 0.00, not just the #N/As.


Yes, that eventually dawned on me... your message and my correction message
"crossed in the mail".

Rick

  #8   Report Post  
Posted to microsoft.public.excel.programming
Len Len is offline
external usenet poster
 
Posts: 162
Default Error Cell "#N/A"

On May 20, 12:16*am, "Rick Rothstein \(MVP - VB\)"
wrote:
Rick, that is the way I was going to suggest doing it as well, but he
mentioned that this was only for the #N/As, so I was assuming that he
could possibly have other errors in the sheet. *Without the loop, it
would change all of the errors to 0.00, not just the #N/As.


Yes, that eventually dawned on me... your message and my correction message
"crossed in the mail".

Rick


Hi ,

Thanks all of you, it works

Regards
Len
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Error Help - Method "Range" of object "_Worksheet" failed. Alan Smith Excel Programming 3 March 15th 07 06:55 PM
What is Error "Method "Paste" of object "_Worksheet" failed? vat Excel Programming 7 February 17th 06 08:05 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM
Getting "compile error" "method or data member not found" on reinstall Bp Excel Programming 1 April 23rd 04 04:42 PM


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