+ Reply to Thread
Results 1 to 7 of 7

Get name from date in VBA

  1. #1
    Registered User
    Join Date
    03-01-2016
    Location
    New Jersey
    MS-Off Ver
    2013
    Posts
    47

    Get name from date in VBA

    Hi all,

    I am looking to get the name of the day from a date using VBA in Excel. I am using this formula but it is not working. Can anyone help?

    Please Login or Register  to view this content.
    Range("B10:B200").Formula = "=IF(A10="""","""",WEKKDAYNAME(A10, "dddd"))"

  2. #2
    Registered User
    Join Date
    03-17-2017
    Location
    Hell
    MS-Off Ver
    2010
    Posts
    172

    Re: Get name from date in VBA

    Weekdayname?

  3. #3
    Registered User
    Join Date
    03-17-2017
    Location
    Hell
    MS-Off Ver
    2010
    Posts
    172

    Re: Get name from date in VBA

    =TEXT(A10,"dddd")

    copy it down

  4. #4
    Registered User
    Join Date
    03-17-2017
    Location
    Hell
    MS-Off Ver
    2010
    Posts
    172

    Re: Get name from date in VBA

    To ensure no blanks use:

    =IF(A10<>0,TEXT(A10,"dddd"),"")
    Last edited by LewisJ; 03-31-2017 at 04:10 PM.

  5. #5
    Registered User
    Join Date
    03-01-2016
    Location
    New Jersey
    MS-Off Ver
    2013
    Posts
    47

    Re: Get name from date in VBA

    I had originally tried that but it doesn't seem to work in VBA. I keep getting a Syntax error. I'm thinking that "Text" is not able to be used in VBA. It works fine as a normal formula in Excel but not in a VBA code

  6. #6
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2021
    Posts
    5,981

    Re: Get name from date in VBA

    Try this ...

    Range("B10:B200").FormulaR1C1 = "=IF(RC[-1]="""","""",TEXT(RC[-1],""dddd""))"

  7. #7
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Get name from date in VBA

    There is a built in VBA function for this.

    WeekDayName

    Takes 3 args. Day of the week index number (1-7), True/false for abbreviated name, and index number for first day of the week.

    You can combine this with the VBA Weekday function. The Weekday function returns the index number representing the day of the week from a date. 2 args, date and an index number or vbConst representing what day of the week starts a week.

    Together they would look like:

    Please Login or Register  to view this content.
    Instead of debug.print you could change this to a variable to store the day of the week or set it as a the value of a range object.

    If you need to use it for a column of cells you could loop the cells and use the date from a cell as the date argument of weekday.

    Hope this helps

+ 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] Change Date with Date Picker If Date Less Than 7 Days From Another Date
    By Macfool in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2016, 09:10 AM
  2. Week to date, Month to date, Qtr to date and Year to date
    By Neilesh Kumar in forum Excel General
    Replies: 4
    Last Post: 06-10-2016, 08:53 AM
  3. [SOLVED] Formula to compare date (including month and year) from a listed date to today's date
    By mhewitson15 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-11-2014, 05:31 PM
  4. Counting if data falls on date between Start Date, End Date or Possible End Date
    By JessHasQuestions in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 07-26-2014, 08:01 AM
  5. Replies: 1
    Last Post: 10-02-2012, 02:42 PM
  6. Replies: 1
    Last Post: 09-28-2012, 08:52 AM
  7. Replies: 7
    Last Post: 11-16-2008, 05:48 PM

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