如果工作表上的单元格值为 false,则 VBA Msgbox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16899292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Msgbox if cell value is false on worksheet
提问by Mowgli
I have this code it works fine but I only have 1 problem.
我有这个代码它工作正常,但我只有 1 个问题。
it doesn't work way I would like it to.
它不会像我希望的那样工作。
I want it to Pop up msgbox every time I change the change.
if cell E45
value is not "True"
then when I change to different sheet I want it prompt me msg saying "Records DO NOT Match, would you still like to continue?"
我希望它每次更改更改时都弹出 msgbox。
如果单元格E45
值不是,"True"
那么当我更改为不同的工作表时,我希望它提示我 msg 说"Records DO NOT Match, would you still like to continue?"
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E45") <> "TRUE" Then
MsgBox "Records Do Not Match"
End If
End Sub
回答by Joshua Honig
You need to change two things:
你需要改变两件事:
First, you need to be using the Workbook_SheetActivate
eventto capture when you have selected a different sheet. Next, you should be comparing to the literal True
value, not the string "TRUE"
:
首先,当您选择不同的工作表时,您需要使用该Workbook_SheetActivate
事件进行捕获。接下来,您应该与文字True
值进行比较,而不是字符串"TRUE"
:
The following code should go in the ThisWorkbook
module:
ThisWorkbook
模块中应该包含以下代码:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Range("E45") <> True Then
MsgBox "Records do not match"
End If
End Sub
回答by Steph Locke
Amend "TRUE" to TRUE so that it checks for the boolean, not the string "true"
将 "TRUE" 修改为 TRUE,以便检查布尔值,而不是字符串 "true"