+ Reply to Thread
Results 1 to 3 of 3

Division by zero in vba error

  1. #1
    Registered User
    Join Date
    10-20-2011
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    98

    Division by zero in vba error

    I am trying to assign a variable in VBA but when the division is by zero i get an error.

    I would like to replace the zero with a figure to pass the error.

    dim Variable1 as double, Variable2 as double,
    Variable1 = Range("A1).value
    Variable2 = Range("A2).value

    Dim PercentReq as double

    PercentReq = Variable1/Variable2*100

    "runtime error"
    Division by Zero


    Thanks for any help

  2. #2
    Registered User
    Join Date
    10-20-2011
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    98

    Re: Division by zero in vba error

    Or in other words how can i get this spreadsheet formula to work in vba

    =IFERROR(A1/A2*100,500)

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Division by zero in vba error

    Probably should wrap your sample code in code tags for easier reading/copying.

    I would like to replace the zero with a figure to pass the error.
    If I understand correctly, this would usually be accomplished using an If...Then statement. http://msdn.microsoft.com/en-us/libr...ice.15%29.aspx
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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