+ Reply to Thread
Results 1 to 13 of 13

Is it possible to have formula change depending on Day of Week

  1. #1
    Forum Contributor
    Join Date
    09-09-2008
    Location
    Middlesbrough, England
    MS-Off Ver
    2007
    Posts
    174

    Is it possible to have formula change depending on Day of Week

    Hi,

    I currently have a formula "=VLOOKUP(B2,0410!B:C,2,FALSE)"

    0410 = Todays date in DDMM format

    Each day a new sheet is created and the formula looks at the previous day.

    EG
    0410 = 4th October and the formula within this sheet will be "=VLOOKUP(B2,0310!B:C,2,FALSE)"

    0510 = 5th October and the formula within this sheet will be "=VLOOKUP(B2,0410!B:C,2,FALSE)"

    The tricky part is when it is a Monday i want the formula to look 3days back.

    So for this week it looks like this:
    0310 = and the formula within this sheet will be 3rd October (But looking at data for 30th September) "=VLOOKUP(B2,3009!B:C,2,FALSE)"

    I have created a templated and replaced the date needed with "template". What i am wanting is a vb code that will change "template in the formula below with the required date".

    "=VLOOKUP(B2,template!B:C,2,FALSE)"

    Any suggestions?
    Last edited by batchy; 10-07-2011 at 05:59 AM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Is it possible to have formula change depending on Day of Week

    You could make that formula "dynamic" to always give you the right sheet referring to the previous working day, i.e.

    =VLOOKUP(B2,INDIRECT(TEXT(WORKDAY(TODAY(),-1),"ddmm")&"!B:C"),2,FALSE)
    Audere est facere

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Is it possible to have formula change depending on Day of Week

    Do you need a macro?

    How about =VLOOKUP(B2,INDIRECT(TEXT(IF(WEEKDAY(TODAY(),2)=1,TODAY()-3,TODAY()-1),"mmdd") & "!B:C"),2,FALSE)

  4. #4
    Forum Contributor
    Join Date
    09-09-2008
    Location
    Middlesbrough, England
    MS-Off Ver
    2007
    Posts
    174

    Re: Is it possible to have formula change depending on Day of Week

    I have tried both formula's without success.

    Attached is a stripped down version of the spreadsheet. If can review and advise i would appreciate it.

    Also concerned the that the forumla will only look to the last day. This becomes an issue on Mondays when i need to spreadsheet to look at Fridays data.
    Attached Files Attached Files

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Is it possible to have formula change depending on Day of Week

    Hello batchy - they both work for me (although I had to change "mmdd" in Andrew's to "ddmm").

    See attached where I used my suggestion in Template C2:C3 and a modified version of Andrew's in D2:D3.

    Both will also work on a Monday to get the previous Friday (you can test that by changing TODAY() in the formula to a cell reference and putting various dates in that cell to see what happens......of course you'll need the relevant sheets for any test dates)

    My suggestion with WORKDAY can also be used to exclude holiday dates if you wish (you need a list of holidays), see WORKDAY help for more....
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    09-09-2008
    Location
    Middlesbrough, England
    MS-Off Ver
    2007
    Posts
    174

    Re: Is it possible to have formula change depending on Day of Week

    Many thanks for the speedy responce.

    However still having issues..

    I have input the formula provided on the 5th so in theory it should be pulling the data from the 4th but i get #REF error...

    EG.
    If you look at worksheet "0510" and cell C2. The formula within this cell is pulling data from 0410 but I have to manually input 0410 and need to change this everytime I create a new day. I have inputted the formulas provided and getting #REF.

    You can see this error from the attachment also provided by Daddy.
    Last edited by batchy; 10-06-2011 at 05:39 AM.

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Is it possible to have formula change depending on Day of Week

    Here's your example sheet back with the (slightly modified) formula I provided in column D on the sheet for the 5th.

    Seems to be working fine to me - so is there something different about your live workbook, as opposed to your example one?
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    09-09-2008
    Location
    Middlesbrough, England
    MS-Off Ver
    2007
    Posts
    174

    Re: Is it possible to have formula change depending on Day of Week

    Thanks, its 50/50 at the moment.

    Appears to work on a new day but if you look at the 5th and remove or change the dates in column C it affects the outcome in the new formula when it should only the data from the 4th affecting this.

  9. #9
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Is it possible to have formula change depending on Day of Week

    That's because today is the 6th, so it evalutes TODAY()-1 to 0511 and looks up on that sheet, which is the same sheet.

    Do you actually want it to work on the date from the sheet title and not today's date?

    Edited to add: If so I'm going to have to concede to Daddylonglegs and use the WORKDAY function...

    =VLOOKUP(B2,INDIRECT(TEXT(WORKDAY(DATE(YEAR(TODAY()),VALUE(RIGHT(CELL("FileName",A1),2)),VALUE(LEFT(RIGHT(CELL("Filename",A1),4),2))),-1),"ddmm") & "!B:C"),2,FALSE)
    Last edited by Andrew-R; 10-06-2011 at 06:47 AM.

  10. #10
    Forum Contributor
    Join Date
    09-09-2008
    Location
    Middlesbrough, England
    MS-Off Ver
    2007
    Posts
    174

    Re: Is it possible to have formula change depending on Day of Week

    Thanks Andrew.

    Was down to user error on my part! Working and extremly happy! Will this also take into consideration bank holidays?

    Many Thanks

    Chris

  11. #11
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Is it possible to have formula change depending on Day of Week

    WORKDAY function allows you to exclude holidays too. The standard function

    =WORKDAY(A1,B1,Holidays)

    Which formula are you using?

    In my original you'd put holidays in like this

    =VLOOKUP(B2,INDIRECT(TEXT(WORKDAY(TODAY(),-1,holiday_range),"ddmm")&"!B:C"),2,FALSE)

    Where holiday_range is a named range where you list all holiday dates

  12. #12
    Forum Contributor
    Join Date
    09-09-2008
    Location
    Middlesbrough, England
    MS-Off Ver
    2007
    Posts
    174

    Re: Is it possible to have formula change depending on Day of Week

    Daddylonglegs also thanks to yourself for the support.

    The formula i have been using is:

    =VLOOKUP(B2,INDIRECT(TEXT(IF(WEEKDAY(TODAY(),2)=1,TODAY()-3,TODAY()-1),"ddmm") & "!B:C"),2,FALSE)

    If i then need to input a holiday range what format does that need to be in in? DDMM?

  13. #13
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Is it possible to have formula change depending on Day of Week

    It needs to be a range, i.e. a range of cells. A1:A10, for example, with the cells in that range containing holiday dates.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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