when cell C1 is changed to between midnight and 7am an error is generated in cells C2 and C12
when cell C1 is changed to between midnight and 7am an error is generated in cells C2 and C12
That is correct.
The earliest time in the table is 07:01, so anything before that will create an error. To prevent it you will need to add an earlier time frame to the table.
To suppress the error you could use an IFERROR such as;
Formula:Please Login or Register to view this content.
Or;
Formula:Please Login or Register to view this content.
to start with, Please update your profile as necessary to properly reflect the exact version(s) of Excel your question relates to. Members tailor answers based on your Excel version. Your profile says 2003, but your file indicates at least 2007
1. you are testing if(WEEKDAY(B3)=1, but B3 contains a single number value. Why not just say if(B3=1?
2. instead of this...
TIME(HOUR($C$1),MINUTE($C$1),SECOND($C$1))
just use
=MOD(C1,1)
3. add an extra row to the top of your tables with 0:00 - off-peak in
1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
2. If your question is resolved, mark it SOLVED using the thread tools
3. Click on the star if you think someone helped you
Regards
Ford
Thank you guys. This was my first time on any forum. No matter what I tried I couldn't get it to work. Now with your help it works like magic.
Repeating Ford's comments in post #4.
If you update your profile so that we know which version of excel you are working with then we can most likely provide you with better answers.
Ford mentioned that you don't need the WEEKDAY(B3) function as B3 only contains a single digit, but B3 contains the formula, =WEEKDAY(C1). With this in mind, you dont need B3 at all, you can just skip straignt to WEEKDAY($C$1) in your lookup formula.
If you read the help file and look at the optional parameters of WEEKDAY, you will see that you can change it to move the start of the week as needed, by changing that so that the week starts on Monday instead of Sunday, you don't need to check the weekday twice, only if it is before Saturday.
Also, if you try to avoid repeating sections of formula when you don't need to, it can be easier to edit and troubleshoot when needed. As the only part of the formula that changes is the lookup range based on the weekday, you only need to define that range based on the result of the logical test, not the entire vlookup formula.
Combining all of the points raised by Ford and myself, you could shorten your whole formula to
=VLOOKUP(MOD($C$1,1),IF(WEEKDAY($C$1,2)<6,H1:I5,H7:I8),2)
and still achieve the same result.
Of course, this still doesn't take into consideration that times before 07:01 will return an error. Your first post contains a statement, "when cell C1 is changed to between midnight and 7am an error is generated in cells C2 and C12"not a question, you have told us what happens but not given us any hint as to what you want to happen in that time frame, which is why the replies you recieved contain short and vague answers.
In short.
Correct Office version in your profile = More suitable suggestions.
Better information in your question = better suggestions.
I could make the list longer, but I think you get the idea
Good stuff!! Happy to help and thanks for the feedback
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks