Home » excel » excel vba – Comparing percentage values in VBA

excel vba – Comparing percentage values in VBA

Posted by: admin May 14, 2020 Leave a comment

Questions:

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.

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

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!

How to&Answers:

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

So change your code to

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