Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refinement to Condition Detection routine 1

Status
Not open for further replies.

MeGustaXL

Technical User
Aug 6, 2003
1,055
GB
Hi All,
I started with a simple row of data like this:
Code:
	A		B	C			D
1	Engine	30	=M*(-LN(RAND()))	=IF(C1<B1,1,0)
I have a looping VBA routine which adds the values in column C to a running total variable ‘Total_T’ when there is a ‘1’ in column D.

If the table expands like this:
Code:
	A		B	C			D
1	Engine	30	=M*(-LN(RAND()))	=IF(C1<B1,1,0)
2	Gearbox	300	=M*(-LN(RAND()))	=IF(C2<B2,1,0)
3	Suspension	500	=M*(-LN(RAND()))	=IF(C3<B3,1,0)
4	Steering	500	=M*(-LN(RAND()))	=IF(C4<B4,1,0)
5	Brakes	120	=M*(-LN(RAND()))	=IF(C5<B5,1,0)
How do I code the thing to detect each occurrence of a ‘1’ in column D, and add the corresponding value from column C to ‘Total_T’

At the moment, I’m detecting the presence of a ‘1’ with the array formula “{=IF(D1:D5=1,1,0)}” which gives a ‘1’ if any of the cells is equal to 1.


And P.S. How do I put tables like this in my post so they line up nicely? [lookaround]


Chris

Varium et mutabile semper Excel

 
Chris,

Maybe I missed the point, here, but the seemingly* obvious solution would be cell e1 =d1*c1. Since 0 * Anything = 0, and 1 * Anything = Anything you are left with the numbers you want to sum. Fill down and auto-sum. Job done! :)



*seemingly = I probably read the post wrong!

Comaboy
 
Thanks Comaboy,

You're absolutely right, of course, and it's me that's in a coma! Have a STAR just for being sentient [lol]

I didn't fully explain what I want to do, however.

Having detected 1's against, say the Engine and Steering, I need to report elsewhere that they have failed at for example, 29.8 and 158.6 respectively. I'm after a kind of Leftwards-looking conditional Lookup...

[idea] Wait a minute - there's something about that in FAQs; I'll have a dredge and see what's there.


Chris

Varium et mutabile semper Excel

 
LOL! It's usually ME not seeing the wood for the trees! :) Great what I fresh pair of eyes can see, eh!

It *sounds* like you're after the VLookUp function, btw!

..or maybe a "back sheet" linked to the main data and sorted...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top