在子中使用公式

他们是

我最初的问题是如何在if- > then语句中使用函数的输出,而Shai的帮助非常有帮助(此处:在另一个表达式中使用aformula的输出)。

不过,我现在想做的是在子程序中使用此功能。所以我有这个子(目前还不完整):

Private Sub CommandButto1_click()
Dim answer As Integer
Dim Response As VbMsgBoxResult
Dim late As VbMsgBoxResult

answer = MsgBox("Price for only one product?", vbYesNoCancel + vbQuestion, "Payment")
If answer = vbYes then
   late = MsgBox("Is the customer late and has to be charged extra?", vbQuestion + vbYesNoCancel)

   If late = vbYes then 
       MsgBox "mergesize function here"
   End If
End If

End Sub

它可以正常工作,但是它说的是-MsgBox“此处的合并大小函数”是我要添加如下函数的地方:

Public Function MergeSize(r As Range) As Long

MergeSize = r(1).MergeArea.Cells.Count

If MergeSize <= 10 Then
    MergeSize = MergeSize * 70
Else
    MergeSize = MergeSize * 65
End If

End Function

另一个问题是,我可以将函数的输出发送为null并仅将其显示在msgbox中吗?

Shai Rado

尝试类似下面的代码。我标记了我添加了调用的代码的位置Function MergeSize我已经用作Range("B2")合并范围。

代码

Private Sub CommandButto1_click()

Dim answer As Integer
Dim Response As VbMsgBoxResult
Dim late As VbMsgBoxResult

answer = MsgBox("Price for only one product?", vbYesNoCancel + vbQuestion, "Payment")
If answer = vbYes Then
   late = MsgBox("Is the customer late and has to be charged extra?", vbQuestion + vbYesNoCancel)

   If late = vbYes Then
        '===== Added the 3 lines below =====
        Dim ExtraCharge As Long

        ExtraCharge = MergeSize(Range("B2")) '<-- Range("B2") is a Merged Cells
        ' === Ver 2.0 - to use with ActiveCell ===
        ExtraCharge = MergeSize(ActiveCell) '<-- ActiveCell is a Merged Cells

        MsgBox "Extra Charge is " & ExtraCharge
   End If
End If

End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章