![]() |
#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 |
#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 |
#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 |
All times are GMT +1. The time now is 07:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com