ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   compare values (https://www.excelbanter.com/excel-programming/353598-compare-values.html)

[email protected][_2_]

compare values
 
Hi, is it possible with vba, to compare values, give or take 1. eg x =
15 and y = 16. If x(+ or -1) = y(+ or -1) then............ In reality
what Ihave is something like 16.1111111 and 16.111112, I just want the
whole numbers, eg the 16, the .1111 is not needed, although its part of
the eqaution.
Regards Robert


broro183[_38_]

compare values
 

Hi Robert

This is not a VBA solution but may satisfy your needs...

Insert a new column (if needed) & type in:
=IF(ROUND(A1,0)=ROUND(B1,0),"approx match", "rounded values don't
match")

Change the cell references as required & the True/False statements.

This will compare the two values after rounding them to the nearest
whole number. Depending on your exact requirements, either of the
functions "roundup(reference,# of decimals)" or "rounddown(reference,#
of decimals)" / "int(reference)" may be more appropriate to use in your
If statement (type "round" into Excel help for more details).

Rob Brockett
NZ
Always learning & the best way to learn is to experience...


--
broro183
------------------------------------------------------------------------
broro183's Profile: http://www.excelforum.com/member.php...o&userid=30068
View this thread: http://www.excelforum.com/showthread...hreadid=513601


K Dales[_2_]

compare values
 
What you want is one of the following:
1) To round up or down to the nearest whole number
If Round(x,0) = Round(y,0) Then....
e.g. Round(16.111,0)=16 while Round(16.500001,0)=17
2) To truncate any decimal points:
If Int(x) = Int(y) Then...
e.g. Int(16.99999) = 16
3) To accurately check if y is in a +/- 1 unit range around x:
If ABS(x-y)<=1 Then...
--
- K Dales


" wrote:

Hi, is it possible with vba, to compare values, give or take 1. eg x =
15 and y = 16. If x(+ or -1) = y(+ or -1) then............ In reality
what Ihave is something like 16.1111111 and 16.111112, I just want the
whole numbers, eg the 16, the .1111 is not needed, although its part of
the eqaution.
Regards Robert



[email protected][_2_]

compare values
 
Thankyou both for your replys, Ive gone with number 2, f Int(x) =
Int(y) Then.. This is perfect for me.
Regards Robert


broro183[_39_]

compare values
 

Pleased to be able to help :-)

Rob Brockett
NZ
Always learning & the best way to learn is to experience...


Wrote:
Thankyou both for your replys, Ive gone with number 2, f Int(x) =
Int(y) Then.. This is perfect for me.
Regards Rober


--
broro18
-----------------------------------------------------------------------
broro183's Profile:
http://www.excelforum.com/member.php...fo&userid=3006
View this thread: http://www.excelforum.com/showthread.php?threadid=51360



All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com