Comparison operators as parameters

hagea_dan

New Member
Joined
Aug 14, 2014
Messages
19
Hi everyone,

I have a set of numbers that must be analized with the comparison operators. It would be really efficient if I could pass these operators as paramaters.
I tried to solve this with the Evaluate function and it works when I compare whole numbers but when I switch to decimal numbers it gives me the type mismatch error.
Can someone please explain why this code doesn't work for decimal numbers?

Code:
Sub test(op1 As String)
Dim c As Range


For Each c In ActiveSheet.Range("A1:A10")
    If Evaluate(c.Value & op1 & c.Offset(0, 1)) Then MsgBox "It works"
Next c
End Sub

Sub caller()
test "<"
End Sub

Here is a data sample that the code must run on.

12
23
0,1270,0841
0,1080,0812

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi everyone,

I have a set of numbers that must be analized with the comparison operators. It would be really efficient if I could pass these operators as paramaters.
I tried to solve this with the Evaluate function and it works when I compare whole numbers but when I switch to decimal numbers it gives me the type mismatch error.
Can someone please explain why this code doesn't work for decimal numbers?

Code:
Sub test(op1 As String)
Dim c As Range


For Each c In ActiveSheet.Range("A1:A10")
    If Evaluate(c.Value & op1 & c.Offset(0, 1)) Then MsgBox "It works"
Next c
End Sub

Sub caller()
test "<"
End Sub

Here is a data sample that the code must run on.

12
23
0,1270,0841
0,1080,0812

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>
I get a type mismatch error also, but that is because your "decimal" numbers used a comma for the decimal point but my system using a dot for the decimal point. When I change the commas to a dots, your code works for me without any errors.
 
Last edited:
Upvote 0
I get a type mismatch error also, but that is because your "decimal" numbers used a comma for the decimal point but my system using a dot for the decimal point. When I change the commas to a dots, your code works for me without any errors.

Sometimes another pair of eyes helps alot. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,856
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top