我在一段更大的代码中包含了这段代码,并且在R = ...的行上一直给我一个溢出错误。我不知道该如何解决。有人可以帮忙吗?
Sub AutoUpdateF()
Dim SG2 As Worksheet
Dim SG3 As Worksheet
Dim SG4 As Worksheet
Dim SG5 As Worksheet
Dim Totals As Worksheet
Dim totalslastrow As Long
Dim sg2lastrow As Long
Dim sg3lastrow As Long
Dim sg4lastrow As Long
Dim sg5lastrow As Long
Dim A As Double
Dim B As Double
Dim C As Double
Dim D As Double
Dim E As Double
Dim W As Double
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim V As Double
Dim R As Double
Set SG2 = Sheets("SG2")
Set SG3 = Sheets("SG3")
Set SG4 = Sheets("SG4")
Set SG5 = Sheets("SG5")
Set Totals = Sheets("Totals")
Totals.Select
totalslastrow = Totals.Cells(Rows.count, 6).End(xlUp).Row
totalslastrow = totalslastrow + 1
SG2.Select
sg2lastrow = SG2.Cells(Rows.count, 2).End(xlUp).Row
A = SG2.Cells(totalslastrow, 2)
SG3.Select
sg3lastrow = SG2.Cells(Rows.count, 2).End(xlUp).Row
B = SG3.Cells(totalslastrow, 2)
SG4.Select
sg4lastrow = SG2.Cells(Rows.count, 2).End(xlUp).Row
C = SG4.Cells(totalslastrow, 2)
SG5.Select
sg5lastrow = SG2.Cells(Rows.count, 2).End(xlUp).Row
D = SG5.Cells(totalslastrow, 2)
SG2.Select
sg2lastrow = SG2.Cells(Rows.count, 3).End(xlUp).Row
W = SG2.Cells(totalslastrow, 3)
SG3.Select
sg3lastrow = SG2.Cells(Rows.count, 3).End(xlUp).Row
X = SG3.Cells(totalslastrow, 3)
SG4.Select
sg4lastrow = SG2.Cells(Rows.count, 3).End(xlUp).Row
Y = SG4.Cells(totalslastrow, 3)
SG5.Select
sg5lastrow = SG2.Cells(Rows.count, 3).End(xlUp).Row
Z = SG5.Cells(totalslastrow, 3)
E = A + B + C + D
V = W + X + Y + Z
R = (Abs(E - V) / ((E + V) / 2)) * 100
Totals.Select
Totals.Cells(totalslastrow, 6).Value = R
End Sub