+ Reply to Thread
Results 1 to 12 of 12

Return data based on day of the week

Hybrid View

  1. #1
    Registered User
    Join Date
    11-19-2017
    Location
    Hallsville, Texas
    MS-Off Ver
    365
    Posts
    57

    Return data based on day of the week

    Sheet 1, Column A, Rows 1:7 have data. Row 1 is Sunday, Row 2 is Monday, etc. I would like the file, when opened, to check the current day of the week, look at the data contained in sheet 1, Column A, Rows 1:7 and return the correct data (based on current day of the week) to Sheet 2, Cell A1.

    Thanks for your help.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Return data based on day of the week

    Try adding this code to the ThisWorkbook tab

    Private Sub Workbook_Open()
    Sheets("Sheet2").Cells(1, 1) = Sheets("Sheet1").Cells(Weekday(Date), 1)
    End Sub
    Martin

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Return data based on day of the week

    Something like this...

    Private Sub Workbook_Open()
        Dim wsSrc As Worksheet: Set wsSrc = Sheets("Sheet1")
        Dim wsDest As Worksheet: Set wsDest = Sheets("Sheet2")
        Dim rngSrc As Range: Set rngSrc = wsSrc.Range("A1:A7")
        Dim rngDest As Range: Set rngDest = wsDest.Range("A1")
        Dim found As Range
        With wsSrc
            Set found = rngSrc.Find(What:=Date, LookIn:=xlValues)
            If Not found Is Nothing Then
                rngDest.Value = found.Value
            Else
                MsgBox "No Match"
            End If
        End With
    End Sub
    ...but it's not entirely clear to me if you have a date (1/7/2018) or just the day of the week which is not a date.
    HTH
    Regards, Jeff

  4. #4
    Registered User
    Join Date
    11-19-2017
    Location
    Hallsville, Texas
    MS-Off Ver
    365
    Posts
    57

    Re: Return data based on day of the week

    I guess I figured it would use TODAY() in the code? Of course, I could add the Days of the Week next to the stretches, if necessary

  5. #5
    Registered User
    Join Date
    11-19-2017
    Location
    Hallsville, Texas
    MS-Off Ver
    365
    Posts
    57

    Re: Return data based on day of the week

    Hey, I noticed you Live in Cibolo, I used to live in Schertz.

  6. #6
    Registered User
    Join Date
    11-19-2017
    Location
    Hallsville, Texas
    MS-Off Ver
    365
    Posts
    57

    Re: Return data based on day of the week

    Here is the document
    Attached Files Attached Files

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Return data based on day of the week

    How about this...

    =INDEX(Sheet1!A5:A11,WEEKDAY(TODAY(),2))

    Today() is a volatile function which will return the date upon the opening of the spreadsheet.

    Schertz, you are a long way from there now.
    Attached Files Attached Files
    Last edited by jeffreybrown; 01-13-2018 at 08:26 PM.

  8. #8
    Registered User
    Join Date
    11-19-2017
    Location
    Hallsville, Texas
    MS-Off Ver
    365
    Posts
    57
    Thanks, I’ll give a try. 6 hours North.

  9. #9
    Registered User
    Join Date
    11-19-2017
    Location
    Hallsville, Texas
    MS-Off Ver
    365
    Posts
    57

    Re: Return data based on day of the week

    That worked well. Thanks. Under the same conditions, if I wanted to return a random choice from the list of stretches, what would I change?

    This is what I've tried

    =INDEX(DATA!A19:A21,RANDBETWEEN(1, ROWS(DATA!A19:A21)),1)
    Last edited by NullSpot; 01-14-2018 at 07:43 AM.

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Return data based on day of the week

    Try...

    =INDEX(DATA!A19:A21,RANDBETWEEN(1,3))

    With this formula, every time you make a change to the spreadsheet or select F9, the formula will recalculate.

    Randbetween is Volatile

  11. #11
    Registered User
    Join Date
    11-19-2017
    Location
    Hallsville, Texas
    MS-Off Ver
    365
    Posts
    57

    Re: Return data based on day of the week

    Ok. Is the 3 in this formula representing the 3 rows? If I add more rows I would change this number?

  12. #12
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Re: Return data based on day of the week

    Correct.

    Since A19:A21 covers three rows, I figured you had three different responses to return and they return randomly.

    Just adjust based on the number of different possible responses.

+ 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. Return averages based on day, week, month and year, from dates in column.
    By koalamotorsport in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-25-2016, 11:11 PM
  2. [SOLVED] return week number based on sum value
    By shido in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-12-2015, 08:33 PM
  3. Replies: 28
    Last Post: 07-17-2015, 07:32 AM
  4. [SOLVED] Return a word based off the day of the week
    By The Man With No Name in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-07-2014, 03:34 PM
  5. [SOLVED] check a date and return different values based on time and day of week
    By garyfahy in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-22-2014, 07:26 AM
  6. Replies: 5
    Last Post: 09-25-2013, 01:48 PM
  7. [SOLVED] Return dates based on week selected
    By john dalton in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-13-2013, 08:38 AM

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