需要援助

时间:2015-09-11 07:08:02

标签: excel vba

未定义子或函数: 为什么以及如何解决它?

Sub FormulaSravnenie()

'order: F=Pal, G=Lay, H = Kar, I= SPCB, J=Quantity
'order2: L=pal, M=lay, N=box, O=subbov,P=pcs

If (j2 > f2) Then L2 = RoundDown(j2 / L2)
Else: L2 = 0
End
If (j2 > f2) Then m2 = RoundDown((j2 - f2) / g2)
ElseIf (j2 < f2 And j2 > g2) Then m2 = RoundDown(j2 / g2)
Else: m2 = 0
End
If (j2 > f2) Then n2 = RoundDown((j2 - (f2 + g2)) / h2)
ElseIf (j2 < f2 And j2 > g2) Then n2 = RoundDown(j2 - g2) / h2
ElseIf (j2 < g2 And j2 > h2) Then n2 = RoundDown(j2 / h2)
Else: n2 = 0
End
If (j2 > f2) Then o2 = RoundDown((j2 - (f2 + g2 + h2) / i2))
ElseIf (j2 < f2 And j2 > g2) Then o2 = RoundDown(j2 - (g2 + h2) / i2)
ElseIf (j2 < g2 And j2 > h2) Then o2 = RoundDown(j2 - h2) / i2
ElseIf (j2 < h2 And j2 > i2) Then o2 = RoundDown(j2 / i2)
Else: o2 = 0
End
If (j2 > 0) Then p2 = j2 - (f2 + g2 + h2 + i2)
Else: p2 = 0

End

End Sub

[IMG] http://i60.tinypic.com/hrzs6h.jpg[/IMG]

所以我想从数据F到J行使用这个公式,并将结果放在L到P行。

If (j2 > f2) Then L2 = RoundDown(j2 / L2)
Else: L2 = 0
End

'结果为L 等等下一行和公式

1 个答案:

答案 0 :(得分:0)

您必须使用Application.WorksheetFunction.RoundDown

VBA没有名为RoundDown的本机函数

e.g。

If (j2 > f2) Then L2 = Application.WorksheetFunction.RoundDown(j2 / L2, 2) 
'The function expects a value (your calculation) and the no. of digits after comma
Else: L2 = 0
End