Results 1 to 29 of 29

Thread: [RESOLVED] Weird Math Error in VBA for Excel

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: [RESOLVED] Weird Math Error in VBA for Excel

    The code doesn't seem to match the Excel formula. In the code, you are doing two separate mods, in the Excel formula, you are doing only one mod.

    Setting that aside, as I guessed, there is an order of operations issue.

    With the Excel formula, this is the order things are happening:

    1. The value in B2 is squared
    2. That result is divided by the value in B3
    3. That result is then taken MOD of the value in B4

    In the VBA code you posted, the MOD is happening at step 2, and step 3 is the division. That is why you are seeing different results. The power being an integer or not is not the issue based on what you have posted.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Apr 2016
    Posts
    17

    Re: [RESOLVED] Weird Math Error in VBA for Excel

    Hi Sorry, had multiple copies of code I was testing and pasted the wrong copy, the correct one is shown above.
    The thing is the code as is will work IF only integers are used and it will match the spreadsheet based mod formulas,
    divergence to error only occurs if I use rationals for the power value and or divisor value, that is the only time it
    fails

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2016
    Posts
    17

    Re: [RESOLVED] Weird Math Error in VBA for Excel

    Hi Sorry, had multiple copies of code I was testing and pasted the wrong copy, the correct one is shown above.
    The thing is the code as is will work IF only integers are used and it will match the spreadsheet based mod formulas,
    divergence to error only occurs if I use rationals for the power value and or divisor value, that is the only time it
    fails

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width