Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change #DIV/0! across a range


Hi

I had a problem with a #DIV/0! error and was given some code here that
works very well on the cell it is aimed at, but I was wondering how I
could tweak it so that it would work across a range.

The code is this

Cells(9: "AL").Value = Evaluate("IF(AE9+AC9=0,0,SUM((AE9
/(AE9+AC9))*100))")

As I say this works well, however I have 10 or more different
calculations using variations on the above formula any one of which
could result in the denominator equaling zero. The answer to each of
those calculations are put into a different cell ranging from AL9 to
AS9. I could paste the code above 10times changing the different cell
values in the calculations but is there a simple one line or two piece
of code that will allow me to apply the above formula to a range of
cells in one go. That is it performs all its calculations and then runs
the next bit of code that checks the range AL9 to AS9 and if it finds a
#DIV/0! in the cell it'll change it to 0 (preferably) or even blank.

I've looked at

Range("AF9:AL9").Value = Evaluate("IF(AE9+AC9=0,0,SUM((AE9
/(AE9+AC9))*100))")

Which will put zero in that range but only if AE9+AC9=0 and as I say
each cell contents is based on a different calculation. I've looked at
ERROR.TYPe or IsError type things and I'm just not getting anywhere.

Any help would be greatly appreciated

regards

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile: http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=545233

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Change #DIV/0! across a range

It isn't clear what changes and what stays the same as you move across the
row.

Also, is there a reason to use evaluate or would you be just as happing
putting the formula itself in the cell


Range("AF9:AL9").Formula = "=If(Y9+W9=0,0,Z9/(Y9+W9))"

? range("AL9").Formula
=IF(AE9+AC9=0,0,AF9/(AE9+AC9))
? range("AF9").Formula
=IF(Y9+W9=0,0,Z9/(Y9+W9))

--
Regards,
Tom Ogilvy



"ghobbit" wrote:


Hi

I had a problem with a #DIV/0! error and was given some code here that
works very well on the cell it is aimed at, but I was wondering how I
could tweak it so that it would work across a range.

The code is this

Cells(9: "AL").Value = Evaluate("IF(AE9+AC9=0,0,SUM((AE9
/(AE9+AC9))*100))")

As I say this works well, however I have 10 or more different
calculations using variations on the above formula any one of which
could result in the denominator equaling zero. The answer to each of
those calculations are put into a different cell ranging from AL9 to
AS9. I could paste the code above 10times changing the different cell
values in the calculations but is there a simple one line or two piece
of code that will allow me to apply the above formula to a range of
cells in one go. That is it performs all its calculations and then runs
the next bit of code that checks the range AL9 to AS9 and if it finds a
#DIV/0! in the cell it'll change it to 0 (preferably) or even blank.

I've looked at

Range("AF9:AL9").Value = Evaluate("IF(AE9+AC9=0,0,SUM((AE9
/(AE9+AC9))*100))")

Which will put zero in that range but only if AE9+AC9=0 and as I say
each cell contents is based on a different calculation. I've looked at
ERROR.TYPe or IsError type things and I'm just not getting anywhere.

Any help would be greatly appreciated

regards

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile: http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=545233


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Change #DIV/0! across a range

Oops,
had one wrong cell address:

Range("AF9:AL9").Formula = "=If(Y9+W9=0,0,Y9/(Y9+W9))"
? range("AL9").Formula
=IF(AE9+AC9=0,0,AE9/(AE9+AC9))
? range("AF9").Formula
=IF(Y9+W9=0,0,Y9/(Y9+W9))


--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

It isn't clear what changes and what stays the same as you move across the
row.

Also, is there a reason to use evaluate or would you be just as happing
putting the formula itself in the cell


Range("AF9:AL9").Formula = "=If(Y9+W9=0,0,Z9/(Y9+W9))"

? range("AL9").Formula
=IF(AE9+AC9=0,0,AF9/(AE9+AC9))
? range("AF9").Formula
=IF(Y9+W9=0,0,Z9/(Y9+W9))

--
Regards,
Tom Ogilvy



"ghobbit" wrote:


Hi

I had a problem with a #DIV/0! error and was given some code here that
works very well on the cell it is aimed at, but I was wondering how I
could tweak it so that it would work across a range.

The code is this

Cells(9: "AL").Value = Evaluate("IF(AE9+AC9=0,0,SUM((AE9
/(AE9+AC9))*100))")

As I say this works well, however I have 10 or more different
calculations using variations on the above formula any one of which
could result in the denominator equaling zero. The answer to each of
those calculations are put into a different cell ranging from AL9 to
AS9. I could paste the code above 10times changing the different cell
values in the calculations but is there a simple one line or two piece
of code that will allow me to apply the above formula to a range of
cells in one go. That is it performs all its calculations and then runs
the next bit of code that checks the range AL9 to AS9 and if it finds a
#DIV/0! in the cell it'll change it to 0 (preferably) or even blank.

I've looked at

Range("AF9:AL9").Value = Evaluate("IF(AE9+AC9=0,0,SUM((AE9
/(AE9+AC9))*100))")

Which will put zero in that range but only if AE9+AC9=0 and as I say
each cell contents is based on a different calculation. I've looked at
ERROR.TYPe or IsError type things and I'm just not getting anywhere.

Any help would be greatly appreciated

regards

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile: http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=545233


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change #DIV/0! across a range


Hi Tom

Thanks for your reply
I have cells in the range AF9:AL9. Each cell may or may not contain the
error #DIV/0! depending on the result of the calculation. Once the
calculations have been performed I'd like the code to be able to look
at each individual cell in that range to determine if it contains an
error such as #DIV/0! and if so change it to '0'. If the cell contains
a valid integer then the code will leave it alone and move onto the
next cell in the range.


Sorry for showing my ignorance but I dont understand where the W9 and
Y9 etc comes in. and the lines starting with a question mark - is that
part of the code?

At the moment I have a command button that on clicking works out a lot
of calculations and does so in a certain order. The results of some of
those calculations unfortunately results in zero so when that result
gets used as part of another calculation I get the error code.

This is part of the code I have at the moment and I'm sure theres
probably a better way to do it but I have to keep it simple as I'm not
very conversant with VBA and I need to be able to follow whats going on
- it works and thats what matters to me. I just need to tidy up those
#DIV/0! erros if they appear.

Cells(2, "AF").Value = Evaluate("=SUM((AE10 / (AE10+AC10))*100)") 'Lab
sensitivity
Cells(2, "AG").Value = Evaluate("=SUM((U10 / (U10+Z10))*100)") 'Lab
specificity
Cells(2, "AH").Value = Evaluate("=SUM((AC10 / (AC10+AE10))*100)") 'Lab
FN rate
Cells(2, "AI").Value = Evaluate("=SUM((Z10 / (U10+Z10))*100)") 'Lab FP
Rate
Cells(2, "AJ").Value = Evaluate("=SUM((AE10 / (AE10+Z10))*100)") 'Lab
PPV


Hope this makes it a bit clearer what I'm trying to do

regards

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile: http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=545233

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
How can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
Change Range & Row Hazel Excel Programming 2 March 7th 06 07:11 PM
How do I change a range name back to the underlying data range? Colin Excel Worksheet Functions 1 September 26th 05 05:55 PM
How can I dynamically change the range for Range("A1:M500")? Bij Excel Programming 3 August 25th 05 02:00 AM
Change cell colour for a cell or range within a predefined range Martin[_21_] Excel Programming 2 May 23rd 05 06:16 PM


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