如何将2个变量应用于BeforePrint?

时间:2017-01-19 16:28:06

标签: excel vba excel-vba

在VBA中,如何在打印之前将最小值应用于单元格并检查2个单元格值是否匹配?我在下面尝试过我的自我,而最小值在Cell比较中不起作用吗?

Private Sub Workbook_BeforePrint(Cancel As Boolean)

    If Sheets("PURCHASE_RECEIPT").Range("G31").Value < "0.01" Then
        [g32] = IIf([g27] = [g31], "Yes", "No")
    If ([g32] = "No") Then
        Cancel = True
        MsgBox ("Please fill in payment method fields before printing and check that the totals match")

    End If

End Sub

1 个答案:

答案 0 :(得分:0)

试试这个......

Private Sub Workbook_BeforePrint(Cancel As Boolean)

With Sheets("PURCHASE_RECEIPT")
    If .Range("G31").Value < 0.01 Or .Range("G27").Value <> .Range("G31").Value Then
        Cancel = True
        MsgBox ("Please fill in payment method fields before printing and check that the totals match")
    End If
End With

End Sub