Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thankyou both for your replys, Ive gone with number 2, f Int(x) =
Int(y) Then.. This is perfect for me. Regards Robert |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Compare values on sheet 1 to values on sheet2 | Excel Worksheet Functions | |||
Excel Compare values in columns & display missing values in a new | Excel Discussion (Misc queries) | |||
How do i compare values from two sheet and copy & paste if values match? | Excel Programming | |||
Compare Listbox values with Collection values | Excel Programming |