#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default #DIV0!

When I use this code, I'd like to divide cells, sometimes it's dividing by 0s
which results in #DIV0!, how can i make this return a zero instead? Or am I
using the wrong code?


Range("D59").Select
ActiveCell.FormulaR1C1 = "=(R[-1]C/R[-1]C[1])"
If IsError(ActiveCell.Value) Then
errval = ActiveCell.Value
Select Case errval
Case CVErr(xlErrRef)
ActiveCell.Value = 0
Case Else
'



End Select
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default #DIV0!

Try it this way:

ActiveCell.FormulaR1C1 = "=IF(R[-1]C[1]=0,0,(R[-1]C/R[-1]C[1]))"


--
Hope that helps.

Vergel Adriano


"CV323" wrote:

When I use this code, I'd like to divide cells, sometimes it's dividing by 0s
which results in #DIV0!, how can i make this return a zero instead? Or am I
using the wrong code?


Range("D59").Select
ActiveCell.FormulaR1C1 = "=(R[-1]C/R[-1]C[1])"
If IsError(ActiveCell.Value) Then
errval = ActiveCell.Value
Select Case errval
Case CVErr(xlErrRef)
ActiveCell.Value = 0
Case Else
'



End Select
End If

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default #DIV0!

Awesome!!

"Vergel Adriano" wrote:

Try it this way:

ActiveCell.FormulaR1C1 = "=IF(R[-1]C[1]=0,0,(R[-1]C/R[-1]C[1]))"


--
Hope that helps.

Vergel Adriano


"CV323" wrote:

When I use this code, I'd like to divide cells, sometimes it's dividing by 0s
which results in #DIV0!, how can i make this return a zero instead? Or am I
using the wrong code?


Range("D59").Select
ActiveCell.FormulaR1C1 = "=(R[-1]C/R[-1]C[1])"
If IsError(ActiveCell.Value) Then
errval = ActiveCell.Value
Select Case errval
Case CVErr(xlErrRef)
ActiveCell.Value = 0
Case Else
'



End Select
End If

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
Averaging without #DIV0! Malcolm Excel Worksheet Functions 12 May 28th 10 03:27 PM
#VALUE & #DIV0 tonyalt3 Excel Worksheet Functions 2 January 9th 08 01:46 PM
IRR & #DIV0! David Excel Worksheet Functions 4 January 23rd 07 05:13 PM
I WANT TO HIDE THIS #DIV0! HERNAN Excel Discussion (Misc queries) 9 July 26th 06 07:28 PM
#DIV0/! issues Brento Excel Discussion (Misc queries) 2 February 2nd 06 07:52 AM


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