Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All,
Please see the simplified example below. For i = 1 To 5 cost = (i * apple) / pear If cost = value Then Exit For next i On the second line, instead of exiting the loop when cost is EQUAL to value, I'd like to write code that would exit when it's the CLOSEST to that value. For example, if value was 4.3 I would like it to exit when cost = 4. If this was an array I was working with, I think I would use the match function. Is this possible? Any insight would be greatly appreciated! Thanks. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sounds like you just need a ROUND
IF ROUND(cost,0) = value Then Exit FOR " wrote: Hi All, Please see the simplified example below. For i = 1 To 5 cost = (i * apple) / pear If cost = value Then Exit For next i On the second line, instead of exiting the loop when cost is EQUAL to value, I'd like to write code that would exit when it's the CLOSEST to that value. For example, if value was 4.3 I would like it to exit when cost = 4. If this was an array I was working with, I think I would use the match function. Is this possible? Any insight would be greatly appreciated! Thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Closest Match Formula | Excel Discussion (Misc queries) | |||
index and match closest | Excel Worksheet Functions | |||
index match array function-returning only first match, need last. | Excel Worksheet Functions | |||
closest match | Excel Worksheet Functions | |||
Closest number match help ... | Excel Worksheet Functions |