下面是我正在进行的项目的代码,由于某种原因,我继续在该行发生溢出错误:
totalAmountWeight = (ActiveWorkbook.Worksheets("Product Info").Cells(p, 8).Value) / (ActiveWorkbook.Worksheets("Product Info").Cells(p, 7).Value)
我不确定为什么会出现此错误或如何解决此错误。
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