Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Find a Min positive value

I need some help.
I have two columns with data. In my case it is time - columns "One" and "Two"
I need to find for each value in Two the value in One, that is closest, i.e. I need to substract values from Two with each value from One and to get the MIN non negative value.
Example: 10:11 from "Two" is related to 10:09 from "One" because the min non negative value after a substraction is 0:02

One Two Result
10:00 10:01 0:01
10:03 10:03 0:00
10:06 10:11
10:09 10:13 0:02
10:12




Thanks in advance,

Yakimo

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find a Min positive value

Dim rng as Range
Dim cell1 as Range
Dim cell2 as Range
set rng = Range(Cells(2,1),Cells(2,1).End(xldown))
for each cell2 in Range(Cells(2,2),cells(2,2).End(xldown))
dblDiff = 1
for each cell1 in rng
if cell2-cell1 0 then
if cell2-cell1 < dblDiff then
dblDiff = cell2-cell1
end if
end if
Next
cell2.offset(0,1).value = dblDiff
cell2.offset(0,1).Numberformat:= "hh:mm"
Next

--
Regards,
Tom Ogilvy


"Yakimoto" wrote in message
...
I need some help.
I have two columns with data. In my case it is time - columns "One" and
"Two"
I need to find for each value in Two the value in One, that is closest, i.e.
I need to substract values from Two with each value from One and to get the
MIN non negative value.
Example: 10:11 from "Two" is related to 10:09 from "One" because the min non
negative value after a substraction is 0:02

OneTwoResult
10:0010:010:01
10:0310:030:00
10:0610:11
10:0910:130:02
10:12




Thanks in advance,

Yakimo


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Find a Min positive value

Thanks, Tom

I was just thinking of some array formula in the result column, without
having to write an action macro


"Tom Ogilvy" wrote in message
...
Dim rng as Range
Dim cell1 as Range
Dim cell2 as Range
set rng = Range(Cells(2,1),Cells(2,1).End(xldown))
for each cell2 in Range(Cells(2,2),cells(2,2).End(xldown))
dblDiff = 1
for each cell1 in rng
if cell2-cell1 0 then
if cell2-cell1 < dblDiff then
dblDiff = cell2-cell1
end if
end if
Next
cell2.offset(0,1).value = dblDiff
cell2.offset(0,1).Numberformat:= "hh:mm"
Next

--
Regards,
Tom Ogilvy


"Yakimoto" wrote in message
...
I need some help.
I have two columns with data. In my case it is time - columns "One" and
"Two"
I need to find for each value in Two the value in One, that is closest,

i.e.
I need to substract values from Two with each value from One and to get

the
MIN non negative value.
Example: 10:11 from "Two" is related to 10:09 from "One" because the min

non
negative value after a substraction is 0:02

OneTwoResult
10:0010:010:01
10:0310:030:00
10:0610:11
10:0910:130:02
10:12




Thanks in advance,

Yakimo




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find a Min positive value

In C2
=min(if((B2-$A$2:$A$20)0,B2-$A$2:$A$20))

Entered with Ctrl+Shift+Enter rather than Enter
Then drag fill down column C.


"Yakimoto" wrote in message
...
Thanks, Tom

I was just thinking of some array formula in the result column, without
having to write an action macro


"Tom Ogilvy" wrote in message
...
Dim rng as Range
Dim cell1 as Range
Dim cell2 as Range
set rng = Range(Cells(2,1),Cells(2,1).End(xldown))
for each cell2 in Range(Cells(2,2),cells(2,2).End(xldown))
dblDiff = 1
for each cell1 in rng
if cell2-cell1 0 then
if cell2-cell1 < dblDiff then
dblDiff = cell2-cell1
end if
end if
Next
cell2.offset(0,1).value = dblDiff
cell2.offset(0,1).Numberformat:= "hh:mm"
Next

--
Regards,
Tom Ogilvy


"Yakimoto" wrote in message
...
I need some help.
I have two columns with data. In my case it is time - columns "One" and
"Two"
I need to find for each value in Two the value in One, that is closest,

i.e.
I need to substract values from Two with each value from One and to get

the
MIN non negative value.
Example: 10:11 from "Two" is related to 10:09 from "One" because the min

non
negative value after a substraction is 0:02

OneTwoResult
10:0010:010:01
10:0310:030:00
10:0610:11
10:0910:130:02
10:12




Thanks in advance,

Yakimo






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
Subtracting positive amts from negative and positive from positive bwbmom Excel Worksheet Functions 3 February 12th 10 03:15 PM
find first positive number in column Sheila D Excel Discussion (Misc queries) 7 August 11th 08 07:08 PM
Find first positive value in a column George Excel Discussion (Misc queries) 5 October 27th 07 06:20 PM
FIND POSITIVE VALUE FIRSTROUNDKO via OfficeKB.com Excel Discussion (Misc queries) 2 March 23rd 06 01:43 AM
Find first positive value in row 3 and return date from row 1 rlaw68 Excel Worksheet Functions 3 July 24th 05 04:26 PM


All times are GMT +1. The time now is 12:06 AM.

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"