0

Getting runtime error '6' overflow when i run a macro from a button, but nothing when i run the macro from vba.

Dim sumnands1 As Double
Dim sumnands2 As Double
Dim nands As Double

'sumnands1 = 1070.9915368616
'sumnands2 = 3027.34663906532
sumnands1 = WorksheetFunction.Sum(Range("N4:N369"))
sumnands2 = WorksheetFunction.Sum(Range("O4:O369"))

'the line below is where i am getting an error
nands = 1 - sumnands1 / sumnands2

Worksheets("accuracy").Cells(7, 3) = nands

the code for the button is just call nameofsub

  • 2
    Probably because you're dividing 0 by 0: see [this question](https://stackoverflow.com/questions/45485285/why-is-0-divided-by-0-throwing-an-overflow-error-in-vba). Also a (probably) related point: `Range("N4:N369")` is unqualified, meaning that you've not specified the workbook and worksheet. Implicitly this is a reference to the `ActiveSheet` in the `ActiveWorkbook`. Best practice is to specify the workbook and worksheet. – BigBen Apr 18 '19 at 01:56
  • Yes you were right, the button was on a different page where the ranges = 0. thanks for the help – dingle ben Apr 18 '19 at 02:31

0 Answers0