IF OR AND statement in one formula

Simmo1313

New Member
Joined
May 4, 2015
Messages
39
Hi all,

Having a bit of difficulty here figuring out where I am going wrong with this one. The table below is for a lighting audit. The inputs are in red and the formula in cells J2:AG4 are for monday only. The data set continues AH and onward for each day of the week.

I want to be able to input a "1" in the days Monday to Sunday where the lights are on and I want to put the time which they turn on in column H and when they turn off in column "I"

The formulas in the table J2:AG4 should insert a value of "1" if the light is on at that time.

The formula I have at the moment can do that only if the start time is earlier in the day than the finish time so I'm not sure where my formula is incorrect


Example formula for what I have at the moment is in J2 <i2,a2=1,j1><i2),and(h2>


<i2)),1,0))<i2,b2=1,j1><i2),(and(h2><h2,k2><i2,a2=1,j1><i2),(and(h2><h2,j1>=IF ( OR ( AND ( H2 < I2 , A2 = 1 , J1 > H2 , J1 < I2 ) , ( AND ( H2 > I2 , A2 = 1 , J1 < H2 , J1 > I2 ) ) ) , 1 , 0 )

Sorry, had to put the spaces in so that the post would leave my formula as is.

I'm hoping I should return results displayed below once the formula is correct.



ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1MTWThFSaSuONOFF12am1am2am3am4am5am6am7am8am9am10am11am12pm1pm2pm3pm4pm5pm6pm7pm8pm9pm10pm11pm
211111



7pm7am11111111111
31

11111

5am9pm111111111111111
411111117am8pm111111111111

<tbody>
</tbody>


Any help would be appreciated.</h2,j1></i2),(and(h2></i2,a2=1,j1></h2,k2></i2),(and(h2></i2)),1,0))<i2,b2=1,j1></i2),and(h2></i2,a2=1,j1>
 
Last edited:
I don't think that is the reason because I have actually entered 00:00, 01:00, 02:00 through to 23:00 which excel does recognise as times because it displays 12 am ,1 am into the cell.

I got it to work doing the following.

I inserted 3 columns above the date and time picker like below

ABCDEFGHIJ
1MTWTHFRSASUT/ONT/OFF0:00
2IF ( AND ( A6 = 1 , H6 < I6 , J1 > H6 , J1 < I6 ) , 1 , 0)
3IF ( AND ( A6 = 1 , H6 > I6 , J1 > H6 ) , 1 , 0 )
4IF ( AND ( A6 = 1 , H6 > I6 , J1 < I6 ) , 1 , 0 )
5111117 PM7AMSUM ( J3 : J5 )

<tbody>
</tbody>

<tbody>
</tbody>
I then hide rows 3 , 4 and 5 and copy the formula through for all the dates.

I think the issue was I was trying to have 2 formulas in one cell which contradicted the results of each other.

If anyone has a neater solution then I am all ears....

Simmo1313,
Got it!
On a copy of your worksheet, make sure all the times are entered 'Number-space-AM or PM'.
Format the times to be 24-hour type, ie. '1:00 PM' is '13:00' etc.
Change the value in cell J1 to be the number 24.

Enter the following formula in cell J2:

Code:
=IF(AND(OR($A2=1, $B2=1, $C2=1, $D2=1, $E2=1, $F2=1, $G2 = 1),J$1<>$I2,IF($H2>$I2,OR(J$1>=$H2,J$1<$I2),AND(J$1>=$H2,J$1<$I2))),1,"")

Then copy it across to AG2, then copy J2:AG2 down to J3:AG4.
If you still want AM/PM times, insert a row above Row A and put them there.
Not too bad once I remembered the format issue with times.
Happy 'Lighting Audit'!

Perpa
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,216,101
Messages
6,128,835
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top