比较 VBA 中的百分比值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19678155/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 00:08:14  来源:igfitidea点击:

Comparing percentage values in VBA

excel-vbavbaexcel

提问by user2862496

I have a cell in Excel that has data stored in it in percentage format, for example -8.40% . I want to compare if the value in the cell is less than(in magnitude) -8.5% or not, if yes then some actions will follow.

我在 Excel 中有一个单元格,其中以百分比格式存储数据,例如 -8.40% 。我想比较单元格中的值是否小于(幅度)-8.5%,如果是,则将执行一些操作。

So how do i write a VBA macro code to compare the value?

那么如何编写 VBA 宏代码来比较值呢?

I tried

我试过

`If ActiveSheet.Range(range_name).Value > "-8.50%" Then 
Perform some action`

But this doesn't seem to work.. so how should i do it? Thanks in advance!

但这似乎不起作用..那么我该怎么做呢?提前致谢!

回答by Siddharth Rout

-8.5%is nothing but -8.5/100which ultimately is -0.085

-8.5%什么都不是,但-8.5/100最终是-0.085

So change your code to

因此,将您的代码更改为

If ActiveSheet.Range(range_name).Value > -0.085 Then