+ Reply to Thread
Results 1 to 6 of 6

How to do =WEEKDAY(DATE();2) as vba?

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    How to do =WEEKDAY(DATE();2) as vba?

    I'm stuck with this easy task. I have done some searching, both here in the formus and on Google, but I can't seem to find anything useful. Maybe I'm not using the right query.

    As the title suggests, the following formula does the job:
    Please Login or Register  to view this content.
    Just weekday() I get to work fine, but I need to extract year and month from one place, and then add the day trough a variable.

    I've written some pseudocode explaining what I'm after:
    Please Login or Register  to view this content.
    I've created an example workbook for you to try out.

    Basically, the idea is to check if the date built up from the day in Sheet1 and year and month in Sheet2 is a Saturday or Sunday, and if so, hide the entire row.

    Your help is really appreciated!

    Knut
    Attached Files Attached Files
    Last edited by knutfh; 07-19-2013 at 08:16 AM. Reason: Updated the code to fix some bugs.

  2. #2
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: How to do =WEEKDAY(DATE();2) as vba?

    I found that I at least need to use DateSerial(), changing the For loop to:
    Please Login or Register  to view this content.
    But now I get an error message with "object required" for the testDate variable I made.

  3. #3
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: How to do =WEEKDAY(DATE();2) as vba?

    Consider:

    Please Login or Register  to view this content.
    which is the equivalent to the worksheet formula:

    =WEEKDAY(DATE(2013,12,25))
    Gary's Student

  4. #4
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: How to do =WEEKDAY(DATE();2) as vba?

    Thanks! I will have a look at this later today.

  5. #5
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: How to do =WEEKDAY(DATE();2) as vba?

    I've had a look at it, and got the problem solved myself.

    Here is the code for future reference:

    Please Login or Register  to view this content.
    This Sub also hides any row for a date where the average sum of cells in that row is 0.
    Last edited by knutfh; 07-22-2013 at 01:11 AM. Reason: Added short explaination.

  6. #6
    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
    53,053

    Re: How to do =WEEKDAY(DATE();2) as vba?

    this would be the regular formula to extract the week day number...
    =WEEKDAY(DATE(YEAR(Sheet2!$D$2),MONTH(Sheet2!$D$2),A2),2)
    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

+ 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. If the date is a weekday then...
    By thexanderharris in forum Excel General
    Replies: 3
    Last Post: 02-19-2010, 01:53 PM
  2. Weekday Date()
    By charmedcharmer in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-15-2007, 03:39 AM
  3. Weekday Date List
    By Dave_A in forum Excel General
    Replies: 7
    Last Post: 03-04-2007, 10:53 AM
  4. Show Weekday with date???
    By Rutgers_Excels in forum Excel General
    Replies: 3
    Last Post: 04-05-2006, 10:44 AM
  5. Getting weekday for a date
    By schoujar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-02-2005, 06:05 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