Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default can anyone help me for "#DIV/0!" Error

i am doing some caculations in excel cells, my result is in cell A1,
if the result comes "#DIV/0!" then While executing the following macro, VBA
gives me Debug message. The value of A becomes "Error 2007".
How can i solve this problem?


Sub Postmacro()
A = Cells(1, 1).Value
B = 1.5
if(A<0) then
C = B / A
End if
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default can anyone help me for "#DIV/0!" Error

Hi,

I don't understand the problem. The line
if(A<0) then
ensures you won't get a #DIV/0 error but you could get a type mismatch. I
suggest you change that line to

If a < 0 And IsNumeric(a) Then


Mike


"Arvind Mane" wrote:

i am doing some caculations in excel cells, my result is in cell A1,
if the result comes "#DIV/0!" then While executing the following macro, VBA
gives me Debug message. The value of A becomes "Error 2007".
How can i solve this problem?


Sub Postmacro()
A = Cells(1, 1).Value
B = 1.5
if(A<0) then
C = B / A
End if
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default can anyone help me for "#DIV/0!" Error

On Fri, 26 Sep 2008 00:07:01 -0700, Arvind Mane
wrote:

i am doing some caculations in excel cells, my result is in cell A1,
if the result comes "#DIV/0!" then While executing the following macro, VBA
gives me Debug message. The value of A becomes "Error 2007".
How can i solve this problem?


Sub Postmacro()
A = Cells(1, 1).Value
B = 1.5
if(A<0) then
C = B / A
End if
End Sub



1. It is good practice to explicitly DIM your variables.

You need to test the contents of Cells(1,1) to see if there is an error value:

====================
Option Explicit
Sub Postmacro()
Dim A As Double
Dim r As Range
Dim B As Double
Dim C As Double

Set r = Cells(1, 1)
If IsError(r) Then Exit Sub
A = r.Value
B = 1.5
If (A < 0) Then
C = B / A

End If
End Sub
===================
--ron
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default can anyone help me for "#DIV/0!" Error

Thanks Ron Rosenfeld

"Ron Rosenfeld" wrote:

On Fri, 26 Sep 2008 00:07:01 -0700, Arvind Mane
wrote:

i am doing some caculations in excel cells, my result is in cell A1,
if the result comes "#DIV/0!" then While executing the following macro, VBA
gives me Debug message. The value of A becomes "Error 2007".
How can i solve this problem?


Sub Postmacro()
A = Cells(1, 1).Value
B = 1.5
if(A<0) then
C = B / A
End if
End Sub



1. It is good practice to explicitly DIM your variables.

You need to test the contents of Cells(1,1) to see if there is an error value:

====================
Option Explicit
Sub Postmacro()
Dim A As Double
Dim r As Range
Dim B As Double
Dim C As Double

Set r = Cells(1, 1)
If IsError(r) Then Exit Sub
A = r.Value
B = 1.5
If (A < 0) Then
C = B / A

End If
End Sub
===================
--ron

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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
Shortcut key for "Paste Options" and "Error Checking" buttons? johndog Excel Discussion (Misc queries) 1 October 6th 06 11:56 AM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 09:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"