View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Wild Bill[_2_] Wild Bill[_2_] is offline
external usenet poster
 
Posts: 90
Default Is there more efficient formula?

You received some very good responses that contained very good code that
(at least at a glance) appeared to be good code that you'd be very happy
with. I did think of a couple of aspects that I did not hear addressed
in earlier replies:

When I first looked at this I saw not 16 but 81 possible combinations.
If you haven't already ruled it to be impossible, you should consider if
any circumstances might produce a negative number in any of the 4
elements. (For example you might simply change each "" to "<"). I
know that it doesn't fulfill your subject "more efficient" but it may be
something that you need to program for.

You also speak of "null" when I sense you may really be referring to
"zero" (the value 0). Just be aware that in Excel, and Excel's VBA
code, those two words are significantly different. (Not that it
invalidates what you already have now).

Finally, some smartly coded replies were given to you that were more
versatile, more reusable, more concise, etc. as opposed to simply
"running faster" (which is just my initial impression of what efficiency
refers to). When you say "more efficient" did you mean in terms of
reducing redundant or unnecessarily repeated code, or faster running?

'There are 16 possible combinations of A, B, C & D
(2*2*2*2)
'Each case is examined below. 1 notes not null. 0 notates
null.

'1111 - CASE 1
If A 0 And B 0 And C 0 And D 0 Then
WeightedAvg = ValueA * A + ValueB * B + ValueC * C +
ValueD * D
'0111 - CASE 2
ElseIf A = 0 And B 0 And C 0 And D 0 Then

...
...