gpt4 book ai didi

excel - 需要 BeforeClose 才能处理多个条件

转载 作者:行者123 更新时间:2023-12-04 22:28:10 25 4
gpt4 key购买 nike

我需要在 BeforeClose 事件中添加一些代码,以便用户在将工作表返回给我之前使用所需的缺失/不完整字段的数量进行更新。问题是,如果其中一个条件为假,则工作簿将关闭,而不是转到下一个条件。

我已经研究了这个问题,但我在任何地方都找不到任何带有多个 if 条件的 BeforeClose 事件的示例。

这是我到目前为止所拥有的:

Private Sub Workbook_BeforeClose(Cancel As Boolean)




If Range("CA1").Value > 0 Then

MsgBox Range("CA1").Value & " - ITEM(S) NEED LIST PRICE CORRECTION. There are " & Range("CA1").Value & " item(s) that presently have DEALER COST > LIST PRICE. Please fix pricing for these item(s) as indicated in Column AA."

Else

If Range("BO1").Value > 0 Then

MsgBox Range("BO1").Value & " - ITEM(S) - PRICE JUSTIFICATION MISSING. There are " & Range("BO1").Value & " item(s) that have a 0% price change to Dealer Cost or a negative price change. These items are missing PLM price justification in the comments field. Please add your comments to Column T."

Else

If Range("BQ1").Value > 0 Then

MsgBox Range("BQ1").Value & "- ITEM(S) - NEGATIVE GROSS MARGIN IN DEALER COST. There are " & Range("BQ1").Value & " item(s) that have negative GM and are missing price confirmation. Please confirm price by selecting YES in Column S."
Else


If Range("BS1").Value > 0 Then

MsgBox Range("BS1").Value & " - ITEM(S) WHOSE INCREASE TO DEALER COST IS GREATER THAN 5 PERCENT. There are " & Range("BS1").Value & " item(s) that have a price increase to Dealer Cost greater than 5% and are missing price confirmation. Please confirm price by selecting YES in Column S."

Else



End If
End If
End If
End If

End Sub

如果前一个条件为假,我需要宏移动到下一个条件,而不是关闭工作簿。提前致谢!!!

最佳答案

我相信你错过了 ElseIf零件

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)

If Range("CA1").Value > 0 Then
MsgBox Range("CA1").Value & " - ITEM(S) NEED LIST PRICE CORRECTION. There are " & Range("CA1").Value & " item(s) that presently have DEALER COST > LIST PRICE. Please fix pricing for these item(s) as indicated in Column AA."
ElseIf Range("BO1").Value > 0 Then
MsgBox Range("BO1").Value & " - ITEM(S) - PRICE JUSTIFICATION MISSING. There are " & Range("BO1").Value & " item(s) that have a 0% price change to Dealer Cost or a negative price change. These items are missing PLM price justification in the comments field. Please add your comments to Column T."
ElseIf Range("BQ1").Value > 0 Then
MsgBox Range("BQ1").Value & "- ITEM(S) - NEGATIVE GROSS MARGIN IN DEALER COST. There are " & Range("BQ1").Value & " item(s) that have negative GM and are missing price confirmation. Please confirm price by selecting YES in Column S."
ElseIf Range("BS1").Value > 0 Then
MsgBox Range("BS1").Value & " - ITEM(S) WHOSE INCREASE TO DEALER COST IS GREATER THAN 5 PERCENT. There are " & Range("BS1").Value & " item(s) that have a price increase to Dealer Cost greater than 5% and are missing price confirmation. Please confirm price by selecting YES in Column S."
End If

End Sub

关于excel - 需要 BeforeClose 才能处理多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55816795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com