+ Reply to Thread
Results 1 to 10 of 10

VBA: Help on Ignoring error values / Err.number

  1. #1
    Forum Contributor
    Join Date
    02-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    102

    VBA: Help on Ignoring error values / Err.number

    Hello,

    Primarily i would like asssitance on how to trap "divisible by zero" error and continue the code execution. if this error occurs the value of the variable should be zero or else the actual value ( for instance if it is 1/0 the value of variable should be 0 and if it is 2/4 the value of variable should be 2). Also, would like to know, can err.number be (re)intialized to zero?

    the below code ( unsure why) give me the following result : when run for the first time it gives me 0 and from 2nd time it gives me the value of 1. This happenns whether i use "On error REsume next" or NOT ( the result is same)

    err 9 : Subscript out of range and Err 11 is Division by Zero. why am i getting "subscript out of range" error - i fail to understand. can someone help me out on this?

    Thanks

    Please Login or Register  to view this content.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: Help on Ignoring error values / Err.number

    you shouldn't ever get an error with that and x should always be 0.

  3. #3
    Forum Contributor
    Join Date
    02-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: VBA: Help on Ignoring error values / Err.number

    That was my understanding also..but this code gives me value 1 ( which is in If condition of Err.number=9 !!)

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: Help on Ignoring error values / Err.number

    what does the first message say?
    that could should not ever give you 1 as an output and I can't see how it would, unless your last error was 9 in some code that is calling this routine.

  5. #5
    Forum Contributor
    Join Date
    02-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: VBA: Help on Ignoring error values / Err.number

    msgbox err.number gives me Zero !!

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: Help on Ignoring error values / Err.number

    where is the 1 appearing? If you're not getting an error message, then no error is occurring. as I said I can't see how you'd get 1 - I certainly don't.

  7. #7
    Forum Contributor
    Join Date
    02-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: VBA: Help on Ignoring error values / Err.number

    have you tried testing the code?

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: Help on Ignoring error values / Err.number

    Yes - that's what "I certainly don't" means.

  9. #9
    Forum Contributor
    Join Date
    02-22-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: VBA: Help on Ignoring error values / Err.number

    ..if you are not getting erro message....r u getting the "expected" result? ( what is the value of X's you are getting?

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA: Help on Ignoring error values / Err.number

    I am getting 0 in all 10 cells as expected.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1