Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counting for Minimum Difference Value

e.g. In a worksheet,

Cells

A1=5
B1=3
C1=4
D1=8
E1=1

In G1 for min difference of sum in the range = C1-B1 = 1
In H1 for max difference of sum in the range = D1-E1 = 7

For maximum difference, the max formula can be used but what about the
minimun difference because the min formula cannot give the correct
answer.

How to do this in the range (A1:E1)? Cells value in the are
changing constantly.

Can someone help me?

Thank you.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Counting for Minimum Difference Value

Michael,

How about

=MIN(ABS(A1:D1-B1:E1))

as an array formula, entered with Ctrl-Shift-Enter.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Michael168" wrote in message
...
e.g. In a worksheet,

Cells

A1=5
B1=3
C1=4
D1=8
E1=1

In G1 for min difference of sum in the range = C1-B1 = 1
In H1 for max difference of sum in the range = D1-E1 = 7

For maximum difference, the max formula can be used but what about the
minimun difference because the min formula cannot give the correct
answer.

How to do this in the range (A1:E1)? Cells value in the are
changing constantly.

Can someone help me?

Thank you.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Counting for Minimum Difference Value

On Sat, 11 Oct 2003 10:50:00 +0100, "Bob Phillips"
wrote in
microsoft.public.excel.programming:

"Michael168" wrote in message
...
e.g. In a worksheet,

Cells [ed.] A1=5, B1=3, C1=4, D1=8, E1=1

In G1 for min difference of sum in the range = C1-B1 = 1
In H1 for max difference of sum in the range = D1-E1 = 7

For maximum difference, the max formula can be used but what about the
minimun difference because the min formula cannot give the correct
answer.

How to do this in the range (A1:E1)? Cells value in the are
changing constantly.


Michael,

How about

=MIN(ABS(A1:D1-B1:E1))

as an array formula, entered with Ctrl-Shift-Enter.


Close, but I think that only returns the smallest difference between
neighbouring cells. E.g. swapping C1/D1 in the OP's array {5,3,4,8,1}
giving {5,3,8,4,1}, your formula returns 2, the difference between 5 and
3.

Below is a VBA function which should do it. Put =MinDiff(A1:E1) into G1.
================================================== ==========
Function MinDiff(theRange As Range) As Double

Dim i As Long, j As Long
Dim theDiff As Double
If theRange.Count < 2 Then
MsgBox "You must select a range of at least 2 cells.", _
vbExclamation + vbOKOnly, "Function MinDiff"
Return
End If
MinDiff = Application.WorksheetFunction.Max(theRange)
For i = 1 To theRange.Count - 1
For j = i + 1 To theRange.Count
theDiff = Abs(theRange.Item(i) - theRange.Item(j))
If theDiff < MinDiff Then MinDiff = theDiff
Next j
Next i
End Function
================================================== ==========

--
Michael Bednarek, IT Manager, TGM Ltd, Brisbane, Australia
http://mcmbednarek.tripod.com/ "POST NO BILLS"
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Counting for Minimum Difference Value

Michael,

That's exactly as I read it. As we have to in this game, I made some
assumptions based upon what was said. Although he didn't explicitly say
adjacent cells, the OP said that MAX was easy, but MIN didn't work. I could
see how he could get the max value from any pairing using MAX and MIN, but
not MAX. From this I surmised that he was comparing adjacent cells. Probably
off target, but the full story is rarely there.


Bob

PS you boys were not very convincing today!


"Michael Bednarek" wrote in message
...
On Sat, 11 Oct 2003 10:50:00 +0100, "Bob Phillips"
wrote in
microsoft.public.excel.programming:

"Michael168" wrote in message
...
e.g. In a worksheet,

Cells [ed.] A1=5, B1=3, C1=4, D1=8, E1=1

In G1 for min difference of sum in the range = C1-B1 = 1
In H1 for max difference of sum in the range = D1-E1 = 7

For maximum difference, the max formula can be used but what about the
minimun difference because the min formula cannot give the correct
answer.

How to do this in the range (A1:E1)? Cells value in the are
changing constantly.


Michael,

How about

=MIN(ABS(A1:D1-B1:E1))

as an array formula, entered with Ctrl-Shift-Enter.


Close, but I think that only returns the smallest difference between
neighbouring cells. E.g. swapping C1/D1 in the OP's array {5,3,4,8,1}
giving {5,3,8,4,1}, your formula returns 2, the difference between 5 and
3.

Below is a VBA function which should do it. Put =MinDiff(A1:E1) into G1.
================================================== ==========
Function MinDiff(theRange As Range) As Double

Dim i As Long, j As Long
Dim theDiff As Double
If theRange.Count < 2 Then
MsgBox "You must select a range of at least 2 cells.", _
vbExclamation + vbOKOnly, "Function MinDiff"
Return
End If
MinDiff = Application.WorksheetFunction.Max(theRange)
For i = 1 To theRange.Count - 1
For j = i + 1 To theRange.Count
theDiff = Abs(theRange.Item(i) - theRange.Item(j))
If theDiff < MinDiff Then MinDiff = theDiff
Next j
Next i
End Function
================================================== ==========

--
Michael Bednarek, IT Manager, TGM Ltd, Brisbane, Australia
http://mcmbednarek.tripod.com/ "POST NO BILLS"



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Counting for Minimum Difference Value

Thank you to both of you for the formula and functions code.
I actually needed a module code to exceute for the whole range of the
worksheet automatically write the output in columns G & H.

Regards

Michael Bednarek wrote:
*On Sat, 11 Oct 2003 10:50:00 +0100, "Bob Phillips"
wrote in
microsoft.public.excel.programming:

"Michael168" wrote in

message
...
e.g. In a worksheet,

Cells [ed.] A1=5, B1=3, C1=4, D1=8, E1=1

In G1 for min difference of sum in the range = C1-B1 = 1
In H1 for max difference of sum in the range = D1-E1 = 7

For maximum difference, the max formula can be used but what about

the
minimun difference because the min formula cannot give the

correct
answer.

How to do this in the range (A1:E1)? Cells value in the are
changing constantly.


Michael,

How about

=MIN(ABS(A1:D1-B1:E1))

as an array formula, entered with Ctrl-Shift-Enter.


Close, but I think that only returns the smallest difference between
neighbouring cells. E.g. swapping C1/D1 in the OP's array
{5,3,4,8,1}
giving {5,3,8,4,1}, your formula returns 2, the difference between 5
and
3.

Below is a VBA function which should do it. Put =MinDiff(A1:E1) into
G1.
================================================== ==========
Function MinDiff(theRange As Range) As Double

Dim i As Long, j As Long
Dim theDiff As Double
If theRange.Count < 2 Then
MsgBox "You must select a range of at least 2 cells.", _
vbExclamation + vbOKOnly, "Function MinDiff"
Return
End If
MinDiff = Application.WorksheetFunction.Max(theRange)
For i = 1 To theRange.Count - 1
For j = i + 1 To theRange.Count
theDiff = Abs(theRange.Item(i) - theRange.Item(j))
If theDiff < MinDiff Then MinDiff = theDiff
Next j
Next i
End Function
================================================== ==========

--
Michael Bednarek, IT Manager, TGM Ltd, Brisbane, Australia
http://mcmbednarek.tripod.com/ "POST NO BILLS" *




------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

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
How to determine the minimum difference between values? Eric Excel Discussion (Misc queries) 3 March 9th 09 05:25 AM
minimum and the corresponding value dinesh kumar Excel Worksheet Functions 4 September 12th 07 08:59 PM
How to distribute coins to achieve minimum difference? Eric Excel Discussion (Misc queries) 0 August 29th 07 05:32 AM
How to lookup the minimum, 2nd minimum and 3rd minimum......... Mark McDonough Excel Worksheet Functions 8 July 15th 06 09:39 PM
charting a difference of 2 columns' w/o adding a difference column Wab Charts and Charting in Excel 4 July 27th 05 02:37 AM


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

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

About Us

"It's about Microsoft Excel"