Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Testing each cell for error

Hey guys,

I need a little help.

I have a spreadsheet with a bunch of #N/A, #VALUE! and #DIV/0! errors.
I want to be able to check each cell in a sheet and if a cell is an
error, replace the contents with the string "NA".

I keep getting type mismatch errors though. Not sure how I'm supposed
to approach this. I declared a testValue variable as double (Dim
testValue As Double) and set it equal to the first cell in the
worksheet I want to test. My thinking was that I would make a loop
with an if statement inside it to go through and test each cell, and
replace the contents if an error is found.

However, when I get to the cells that contain errors, I get a type
mismatch error in VBA.

Should I not be declaring the test variable as double? Is there
something else? Not sure how to go about this, any help would be
greatly appreciated.

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Testing each cell for error

one way

Sub findErrors()
Dim cell As Range
For Each cell In Worksheets("sheet1").UsedRange
If IsError(cell.Value) Then
cell.Value = "N/A"
End If
Next

End Sub

--


Gary


wrote in message
ps.com...
Hey guys,

I need a little help.

I have a spreadsheet with a bunch of #N/A, #VALUE! and #DIV/0! errors.
I want to be able to check each cell in a sheet and if a cell is an
error, replace the contents with the string "NA".

I keep getting type mismatch errors though. Not sure how I'm supposed
to approach this. I declared a testValue variable as double (Dim
testValue As Double) and set it equal to the first cell in the
worksheet I want to test. My thinking was that I would make a loop
with an if statement inside it to go through and test each cell, and
replace the contents if an error is found.

However, when I get to the cells that contain errors, I get a type
mismatch error in VBA.

Should I not be declaring the test variable as double? Is there
something else? Not sure how to go about this, any help would be
greatly appreciated.

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Testing each cell for error

That works, thanks :)

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
Testing for error : was 2nd Occurence Rodney New Users to Excel 5 April 29th 05 02:59 AM
Testing a cell Michael Singmin Excel Programming 5 November 29th 03 05:56 AM
testing cell value Thompson, Joseph Excel Programming 1 November 8th 03 09:41 AM
testing the value of a cell Zeraia Excel Programming 3 October 22nd 03 12:58 AM


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