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
  • 2
    Probably because you're dividing 0 by 0: see this question. 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. Commented Apr 18, 2019 at 1:56
  • Yes you were right, the button was on a different page where the ranges = 0. thanks for the help Commented Apr 18, 2019 at 2:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.