excel - 如果不值之间不起作用。excel中的VBA
问题描述
我用 Stackoverflow 解决了很多问题,但我找不到答案。如果不是,那么状态就不是真的,即使它应该是。
dim Val as integer
for i = 1 to 2
Val=.Range("N" & i).Value 'Val is 0 for example
Msgbox(Val) 'to debug what the value is and this example it is 0
If not (300<=Val<=500) then 'this statement is never true even if Value=0
'Do stuff
End If
next i
解决方案
试试这个:
for i = 1 to 2
Val=.Range("N" & i).Value 'Value is 0 for example
Msgbox(Val) 'to debug what the value is and this example it is 0
If Val >= 300 And Val<=500 then ' check if Val is between 300 and 500
'Do stuff
End If
next i
将变量重命名为Val
以区分它和.Value
. 财产
推荐阅读
- python - 将值更改为字符串 Python 中的转换器 Int64
- javascript - 连续文本框验证
- c# - 从一行中选择值 - RadGridView C#
- can-bus - 如何使用 CAPL 程序发送消息
- python - 如何在不分隔字符的情况下打印枚举列表(带有字符)
- c# - ASP.NET:将消息从控制器传递到视图(ViewBag、ViewData 或 TempData)
- php - 如何将动态变量从 PHP 语法转换为 twig
- typescript - Typescript - Morgan 和 logger.stream 导致 lint 错误
- java - Android搜索过滤器在没有结果时显示文本视图
- .net-core-2.1 - 如何将本机二进制文件打包为全局 dotnet 工具