Re: Man in the middle
- From: "Luke Alcatel" <nobody@xxxxxxxxxx>
- Date: Thu, 20 Apr 2006 14:55:12 -0400
Well I never knew of the Median function, probably because it ...
- is not in my Excel 2000 help.
- is not a choice with automatic completion in the VBA editor.
However I would still shy away from it because its syntax is poorly thought
out. It appears to only accept an explicit list of variables, not an array.
If the OP's boss is delighted with his skill in solving the problem, he's
got some woe when the boss wants the median of 1001 items.
BTW, for closure, I'll painfully complete the OP's question:
If dVar1 > dVar2 Then
temp = dVar2
dVar2 = dVar1
dVar1 = temp
End If
If dVar2 > dVar3 Then
temp = dVar3
dVar3 = dVar2
dVar2 = temp
End If
If dVar1 > dVar2 Then
temp = dVar2
dVar2 = dVar1
dVar1 = temp
End If
Note that this is nothing more than an ugly implementation of the bubble
sort algorithm I explained.
Luke
"Tom Ogilvy" <TomOgilvy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9F6BED9C-E26E-4ACB-B1BC-660F746FDF7D@xxxxxxxxxxxxxxxx
If the there are an odd number of variables, the Median functioneliminates
all that for you. If it isn't an odd number, what would be the definitionof
the middle value? <g>for
--
Regards,
Tom Ogilvy
"Luke Alcatel" wrote:
I would advise you not to develop a specialized solution that only works
bossthe case of 3 items since you'll need to re-solve the problem when your
Adecides s/he wants to see the middle (wo)man of 5 items. The general
procedure is to sort your list and take the middle item from the list.
outsimple explanation of bubble sort is:
1. Place your data in an array if N items
2. Create an outer loop that loops from N-1 to 1
3. Create in inner loop that loops from 0 to the value of the outer loop
variable (J).
4. In the inner loop compare item(J) to item (J+1) and swap if they are
byof order.
5. When the outer loop finishes the list is sorted. You can optimize it
innerkeeping track of whether there were any swaps in an iteration of the
yours.loop and the first time there isn't one, your list is sorted.
There are quicker sorts but this is most suitable for a problem like
fromI may have made some (hopefully) minor mistakes by regurgitating this
inmemory but it's a good mental exercise to verify the logic.
Luke
"XP" <XP@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:938B3404-4FCE-4EC5-87DF-F2C34296B740@xxxxxxxxxxxxxxxx
I am using Office 2003 on Windows XP.
In code, I need to work out which variable contains the middle value,
tie.this example, it would be 85. I would guess this needs to be done by
comparing <= and >= and sometimes there could be a two or three way
toIn a
tie, it doesn't matter which one is in the middle...but the code needs
needidentify which variable has been selected. So in the example, I would
workto
know that dVar1 is in the
middle.
Dim dVar1 as Double
Dim dVar2 as Double
Dim dVar3 as Double
dVar1 = Abs(-85)
dVar2 = Abs(95)
dVar3 = Abs(25)
If dVar1 >= dVar2 then ... (what next? I can't crack it!)
Do I have to try every combination to work this out? I can't seem to
out the code to ensure that it always works. Your help is appreciated.
.
- Follow-Ups:
- Re: Man in the middle
- From: Tom Ogilvy
- Re: Man in the middle
- References:
- Re: Man in the middle
- From: Luke Alcatel
- Re: Man in the middle
- Prev by Date: Re: Formula and text in one cell?
- Next by Date: Re: Merge rows depending on the value of the first column
- Previous by thread: Re: Man in the middle
- Next by thread: Re: Man in the middle
- Index(es):
Relevant Pages
|