Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare values on sheet 1 to values on sheet2 Colin Excel Worksheet Functions 2 August 2nd 06 07:19 PM
Excel Compare values in columns & display missing values in a new cpetta Excel Discussion (Misc queries) 1 April 2nd 05 05:51 AM
How do i compare values from two sheet and copy & paste if values match? rozb Excel Programming 0 March 5th 04 12:06 AM
Compare Listbox values with Collection values Stuart[_5_] Excel Programming 2 September 20th 03 01:58 PM


All times are GMT +1. The time now is 04:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"