Hi! Hope you are well.
The "VBA way" is to use VBA's Format function (Replace CELL with the range object for the cell desired): Format(CELL.Value2, "dddd") If you wanted to use the TEXT function, the example given -- I believe -- will return incorrect results. These versions would return the correct result (replace WORKSHEET/CELL): Worksheetfunction.Text(CELL, "dddd") WORKSHEET.evaluate("text(" & CELL.address & ",""dddd"")") WORKSHEET.evaluate("text(" & CELL.value2 & ",""dddd"")") WORKSHEET.evaluate("text(""" & CELL.value & """,""dddd"")") The Format function would be my preference, but of the TEXT function versions, the first is most efficient, then second, then third. The first uses a cell reference to supply the date value, the second a dateserial (Value2 returns a number for dates), the third a text representation of the date (the Value property converts date/time values on the worksheet to VBA's Date datatype, but when you concatenate it with a string, VBA's datatype coercion behavior is to convert it to a text representation using the system locale's short date and/or short time settings). The previous example acquired the cell value via it's Text property, which is dangerous and rarely desired. Text returns the value of the cell as formatted, but if the column is hidden, it returns an empty string. Also, the Day function will cause trouble. It's a common misunderstanding to think it should be used with the Text function, but this is almost never desired. Day returns a number between 1 and 7 to indicate the day of the week. Text formats dates or dateserial numbers, not day numbers. Text will interpret numbers between 1 and 7 as the first 7 days on it's dateserial calendar, which are 1/1/1900 through 1/7/1900. Asa From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] On Behalf Of tangledweb Sent: Wednesday, June 27, 2012 8:23 PM To: excel-macros@googlegroups.com Subject: $$Excel-Macros$$ Re: Can I get the day of the week (e.g. Friday) from the date already encoded in a string? The custom format will not work as I need the data to have the date except for one special test. This worked so thanks Lalit. Evaluate("=Text(Day(""" & Sheets(RawData).Cells(count, BarDate).Text & """), ""dddd"")") Oddly when I used "Sheet1" instead of RawData which is the same sheet I got a subscript out of range but worked fine with the alias. On Tuesday, June 26, 2012 8:47:02 PM UTC-7, tangledweb wrote: If I already have Sheets(RawData).Cells(count, BarDate).Text having a value like 6/26/2012 is there a way to get the day of the week as a number or string for that date that does not require splitting it into its parts and feeding them to some function? If the latter the .net examples I found for that did not make sense to me so how is it done? -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ---------------------------------------------------------------------------- -------------------------- To post to this group, send email to excel-macros@googlegroups.com To unsubscribe, send a blank email to excel-macros+unsubscr...@googlegroups.com -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com To unsubscribe, send a blank email to excel-macros+unsubscr...@googlegroups.com