1

Below is my code for the project I am doing, and for some reason I keep on getting an overflow error at the line:

totalAmountWeight = (ActiveWorkbook.Worksheets("Product Info").Cells(p, 8).Value) / (ActiveWorkbook.Worksheets("Product Info").Cells(p, 7).Value)

I am not sure why this error is occurring or how to fix it.

Private Sub Worksheet_Calculate()
Dim target As Range
Set target = Range("Q1")
Dim p As Long
Dim o As Long

Dim r As Long
Dim Length As Single
Dim Width As Single
Dim Height As Single
Dim totalAmountWeight As Double
Dim i As Integer, intValueToFind As Integer





Dim sheet As Worksheet

Set sheet = ThisWorkbook.Worksheets("Product Info")
'lastrow = sheet.Cells(sheet.Rows.Count, "B").End(xlUp).row
lastrow = Range("B" & Rows.Count).End(xlUp).Row

o = 1
r = 1

If Not Intersect(target, Range("Q1")) Is Nothing Then

For p = 2 To lastrow


Length = ActiveWorkbook.Worksheets("Product Info").Cells(p, 2).Value
Width = ActiveWorkbook.Worksheets("Product Info").Cells(p, 3).Value
Height = ActiveWorkbook.Worksheets("Product Info").Cells(p, 4).Value



totalAmountWeight = (ActiveWorkbook.Worksheets("Product Info").Cells(p, 8).Value) / (ActiveWorkbook.Worksheets("Product Info").Cells(p, 7).Value)

ActiveWorkbook.Worksheets("Backend").Range("O1").Value = totalAmountWeight

Call boxes(Length, Width, Height)
Call boxesLast3(Length, Width, Height)

intValueToFind = 0
For i = 2 To 7    ' Revise the 500 to include all of your values
    If ActiveWorkbook.Worksheets("Backend").Cells(i, 5).Value = intValueToFind Then
        'MsgBox ("Found value on row " & i)
        ActiveWorkbook.Worksheets("Backend").Cells(i, 7).Value = 600
        ActiveWorkbook.Worksheets("Backend").Cells(i, 8).Value = 400
        ActiveWorkbook.Worksheets("Backend").Cells(i, 9).Value = 325

        Else
            'MsgBox ("Value not found in the range!")
            'MsgBox ActiveWorkbook.Worksheets("Backend").Cells(i, 5).Value
    End If
Next i


Call LWextra(Height, Length, Width)
Call HWextra(Height, Length, Width)
Call LHextra(Height, Length, Width)
Call HLextra(Height, Length, Width)
Call WLextra(Height, Length, Width)
Call WHextra(Height, Length, Width)


newamount = ActiveWorkbook.Worksheets("Backend").Range("Q1").Value
dimensions = ActiveWorkbook.Worksheets("Backend").Range("K13").Value

ActiveWorkbook.Worksheets("Backend").Cells(o, 26).Value = newamount
o = o + 1

ActiveWorkbook.Worksheets("Backend").Cells(r, 27).Value = dimensions
r = r + 1

Next p

End If

End Sub
8
  • 1
    Are you dividing it by zero ? Use Debug.Print ActiveWorkbook.Worksheets("Product Info").Cells(p, 7).Value or step through the code. Check the value in Immediate window using Ctrl + G Commented Jun 6, 2016 at 17:13
  • Did you have a look at these: stackoverflow.com/questions/23525290/… or stackoverflow.com/questions/12965805/… or stackoverflow.com/questions/8955488/… ? Commented Jun 6, 2016 at 17:19
  • What are the values for the numbers you are dividing when you get the error? Commented Jun 6, 2016 at 17:26
  • @newguy wouldn't that give a division by zero error? Commented Jun 6, 2016 at 17:28
  • You are also trying to use alphabetical row headers when they need to be numeric using the 'cells()' function. Commented Jun 6, 2016 at 17:30

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.