PC Review


Reply
Thread Tools Rate Thread

Code for dealing with #REF

 
 
Kevin Porter
Guest
Posts: n/a
 
      5th Dec 2007
I have some fields that end up #REF because of deletes that are done. I
would like to look at that field, if it contains #REF then I want that field
to be the sum of all the columns in that row. If it doesn't then I want it
to equal what it equals.

Thanks,

Kevin Porter
 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      5th Dec 2007
You can trap REFs or any kind of errors in cell values like this:

=IF(ISERROR(SUM(A1:A10)),0,SUM(A1:A10))

Excel 2007 has a shorter form:

=IFERROR(SUM(A1:A10),0)

You'd of course replace the 0 with another formula.


--
Jim
"Kevin Porter" <(E-Mail Removed)> wrote in message
news:2D9A50A8-5279-4746-906E-(E-Mail Removed)...
|I have some fields that end up #REF because of deletes that are done. I
| would like to look at that field, if it contains #REF then I want that
field
| to be the sum of all the columns in that row. If it doesn't then I want
it
| to equal what it equals.
|
| Thanks,
|
| Kevin Porter


 
Reply With Quote
 
Kevin Porter
Guest
Posts: n/a
 
      6th Dec 2007
How would I use it when using variables. I am using RowToFind and ColToFind
earlier in the code. But when I try to replace (A1:A10) in the code with
those variables it does not recognize them, of course. I have been playing
with it since your response and not making much headway.

Thanks for your help.

"Jim Rech" wrote:

> You can trap REFs or any kind of errors in cell values like this:
>
> =IF(ISERROR(SUM(A1:A10)),0,SUM(A1:A10))
>
> Excel 2007 has a shorter form:
>
> =IFERROR(SUM(A1:A10),0)
>
> You'd of course replace the 0 with another formula.
>
>
> --
> Jim
> "Kevin Porter" <(E-Mail Removed)> wrote in message
> news:2D9A50A8-5279-4746-906E-(E-Mail Removed)...
> |I have some fields that end up #REF because of deletes that are done. I
> | would like to look at that field, if it contains #REF then I want that
> field
> | to be the sum of all the columns in that row. If it doesn't then I want
> it
> | to equal what it equals.
> |
> | Thanks,
> |
> | Kevin Porter
>
>
>

 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      6th Dec 2007
I gave you a worksheet formula because it wasn't clear to me whether you
were writing code or writing formulas.

While I'm still not sure what you're doing, you can check a cell like this
for an error value:

If IsError(Cells(RowToFind, ColToFind).Value) Then
MsgBox "Error"
End If

or like this:

If IsError(Range("C9").Value) Then
MsgBox "Error"
End If

Or with its range name if you've assigned one.

--
Jim
"Kevin Porter" <(E-Mail Removed)> wrote in message
news:6E8E8340-5BF7-4EB9-A958-(E-Mail Removed)...
| How would I use it when using variables. I am using RowToFind and
ColToFind
| earlier in the code. But when I try to replace (A1:A10) in the code with
| those variables it does not recognize them, of course. I have been
playing
| with it since your response and not making much headway.
|
| Thanks for your help.
|
| "Jim Rech" wrote:
|
| > You can trap REFs or any kind of errors in cell values like this:
| >
| > =IF(ISERROR(SUM(A1:A10)),0,SUM(A1:A10))
| >
| > Excel 2007 has a shorter form:
| >
| > =IFERROR(SUM(A1:A10),0)
| >
| > You'd of course replace the 0 with another formula.
| >
| >
| > --
| > Jim
| > "Kevin Porter" <(E-Mail Removed)> wrote in message
| > news:2D9A50A8-5279-4746-906E-(E-Mail Removed)...
| > |I have some fields that end up #REF because of deletes that are done.
I
| > | would like to look at that field, if it contains #REF then I want that
| > field
| > | to be the sum of all the columns in that row. If it doesn't then I
want
| > it
| > | to equal what it equals.
| > |
| > | Thanks,
| > |
| > | Kevin Porter
| >
| >
| >


 
Reply With Quote
 
Kevin Porter
Guest
Posts: n/a
 
      6th Dec 2007
Yes, reading back over it, it is a bit obscure. Let's try again, because the
second one is close to what I need.

I am writing code that looks at a specific cell (RowToFind,ColToFind) and
checks if it has an error condition, in this case I know it will be a #REF
error. If it is errored then I want to sum all cells from (RowToFind, 5) to
(RowToFind, ColToFind - 1) and write that number into (RowToFind, ColToFind).
The following is the code I tried:

If IsError(Cells(RowToFind, ColToFind)) Then Workbooks("SRA Detailed Payroll
- " & WBDate & ".xls").Sheets("Shreveport").Cells(RowToFind, ColToFind) =
"=Sum(cells(RowToFind, 5):cells(rowtofind, coltofind[-1]))"


I think I am ok up to the =Sum command.

Thanks again for your help and patience.
 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      6th Dec 2007
I think the end of it should go like this:

..Cells(RowToFind, ColToFind) = _
"=Sum(" & Cells(RowToFind, 5).Address(False, False) & ":" & _
Cells(RowToFind, ColToFind - 1).Address(False, False) & ")"

The False's after Address made the references relative. You can drop them
and the parens they are in if you want absolute references.

--
Jim
"Kevin Porter" <(E-Mail Removed)> wrote in message
news:CF7153B8-26CF-45E1-B5A2-(E-Mail Removed)...
| Yes, reading back over it, it is a bit obscure. Let's try again, because
the
| second one is close to what I need.
|
| I am writing code that looks at a specific cell (RowToFind,ColToFind) and
| checks if it has an error condition, in this case I know it will be a #REF
| error. If it is errored then I want to sum all cells from (RowToFind, 5)
to
| (RowToFind, ColToFind - 1) and write that number into (RowToFind,
ColToFind).
| The following is the code I tried:
|
| If IsError(Cells(RowToFind, ColToFind)) Then Workbooks("SRA Detailed
Payroll
| - " & WBDate & ".xls").Sheets("Shreveport").Cells(RowToFind, ColToFind) =
| "=Sum(cells(RowToFind, 5):cells(rowtofind, coltofind[-1]))"
|
|
| I think I am ok up to the =Sum command.
|
| Thanks again for your help and patience.


 
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
Dealing with #VALUE! Maracay Microsoft Excel Misc 3 10th Feb 2009 03:35 PM
Dealing with HTML Code in a memo field. =?Utf-8?B?TUphdEFmbGFj?= Microsoft Access VBA Modules 7 4th Oct 2005 09:52 PM
Dealing with pop-ups Jasons Microsoft Excel Programming 0 7th Nov 2004 03:56 PM
Dealing with CSV MFRASER Microsoft C# .NET 3 23rd Dec 2003 06:41 PM
DEALING WITH ZERO'S John Microsoft Access 3 28th Oct 2003 09:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.