+ Reply to Thread
Results 1 to 7 of 7

vlookup problem

  1. #1
    Registered User
    Join Date
    09-13-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    vlookup problem

    when cell C1 is changed to between midnight and 7am an error is generated in cells C2 and C12
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: vlookup problem

    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.

  3. #3
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: vlookup problem

    To suppress the error you could use an IFERROR such as;
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Or;
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: vlookup problem

    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

  5. #5
    Registered User
    Join Date
    09-13-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: vlookup problem

    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.

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: vlookup problem

    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

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: vlookup problem

    Good stuff!! Happy to help and thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VLOOKUP problem
    By toppman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-10-2013, 10:04 AM
  2. Vlookup problem in a loop with cell property and variable cell problem (long title sry)
    By ExcelsiorLux in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2013, 10:38 AM
  3. Replies: 6
    Last Post: 05-28-2013, 05:08 PM
  4. vlookup? match? index? MULTIPLE criteria for vlookup search problem....
    By aborg88 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-11-2013, 09:56 AM
  5. vlookup problem and count problem
    By thy00123 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-05-2009, 04:31 AM
  6. Problem with VLOOKUP
    By kjg in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-07-2008, 12:54 PM
  7. VLOOKUP Problem
    By Aladin Akyurek in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 09-06-2005, 06:05 PM
  8. [SOLVED] VLOOKUP Problem
    By mr tom in forum Excel Formulas & Functions
    Replies: 24
    Last Post: 09-06-2005, 03:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1