執行以下程式會出現 【執行階段錯誤"11" 除以零】訊息視窗
m = Application.Max(0, Round((.Range("f1") - (B + B.Offset(, 1))) / B.Offset(, 1), 0))
上面程式碼為錯誤描述~~請問要如何修正勒
執行檔案內容如圖檔
Private Sub CommandButton1_Click()
With Sheet1
Set Rng = .Range(.[D5], .[D65536].End(xlUp))
For Each B In Rng
If IsDate(B) And (B + B.Offset(, 1) < .Range("f1")) Then
m = Application.Max(0, Round((.Range("f1") - (B + B.Offset(, 1))) / B.Offset(, 1), 0))
B.Offset(, 3) = B + B.Offset(, 1) + m * B.Offset(, 1)
ElseIf IsDate(B) And (B + B.Offset(, 1) > .Range("f1")) Then
B.Offset(, 3) = B + B.Offset(, 1)
End If
Next
End With
End Sub |