Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I return the weekday name from a date in VBA ?

Posted on 2014-03-14
5
Medium Priority
?
2,086 Views
Last Modified: 2014-03-15
Hi,

I'm trying to return the name of the day of the week from a date but I keep getting a compilation error on the "ddddd" part of the statement...

Dim lWeekday As Long
Dim strWeekdayText As Long

lWeekday = WorksheetFunction.Weekday(("teTrainingDate" & Idx))
strWeekdayText = WorksheetFunction.Text(lWeekday, “ddddd”)

Any ideas ?

Thanks
Toco
0
Comment
Question by:Tocogroup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39929825
Hi,

the function Text in this case waits for a date
I do not see in your code that
"dddd" 4d only for the date in letters
You can use format as well

strWeekdayText = Format(yourDate, “dddd”)

Open in new window


EDIT I do not understand you frist line of code

How do you want to find a weekday with a "teTrainingDate" & Idx, it's no date

Regards
0
 

Author Comment

by:Tocogroup
ID: 39929884
Hi,

I'm getting a Run-time error 13 Type mismatch

Does the date have to be in a particular date format ?

strWeekdayText = WorksheetFunction.Text("teTrainingDate" & Idx, "ddddd")

My date is being held as dd-mmm-yyyy
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39929896
Hi,

what is the value of
"teTrainingDate" & Idx
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39930024
Hi,

You cannot refer to a variable via a string like in your code

pls try (add cases for your different dates indexes if necessary)

Dim lWeekday As Long
Dim strWeekdayText As String 'Edited
Dim strDate As String

Select Case Idx
    Case 1
        strDate = teTrainingDate1
    Case 2
        strDate = teTrainingDate2
    Case 3
        strDate = teTrainingDate3
    Case 4
        strDate = teTrainingDate4
        
    ' And so on
End Select
strWeekdayText = Format(strDate, "dddd")

Open in new window

Regards
0
 

Author Closing Comment

by:Tocogroup
ID: 39931137
Thanks for that
Toco
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question