Thanks for the info, Tex. I already know about the available Excel formats that can be accessed via the Format() statement in VBA for Excel as well as theMessage 1 of 6 , Jul 17, 2010View Source
Thanks for the info, Tex.
I already know about the "available" Excel formats that can be accessed via the "Format()" statement in VBA for Excel as well as the "Selection.NumberFormat" statement, also available in VBA for Excel. The "Format()" statement requires a cell coordinate, such as "Format(B3, "yyyymmdd")" which the "Selection.NumberFormat" statement doesn't. However, I have an Excel macro (copy attached including my additions, can be read using any text editor) that was published in the May 2008 issue of "(Australian) PC User : Excel Macro of the Month" which allows the user to apply a format to a cell by selecting the format from a list instead of having to use the builtin Excel "process". Some of the desired ISO8601:2004 "formats" can't be constructed in this way. That is, the following code segment shows what I am after and these formats already work as expected:
Select Case ListBox1.ListIndex
Selection.NumberFormat = "ddd, dd mmm yyyy"
Selection.NumberFormat = "dd mmm yyyy"
Selection.NumberFormat = "ddd, dd-mmm-yyy"
Selection.NumberFormat = "dd-mmm-yyyy"
Selection.NumberFormat = "ddd, dd mmm yyyy hh:mm:ss"
Selection.NumberFormat = "dd mmm yyyy hh:mm:ss"
Selection.NumberFormat = "ddd, dd-mmm-yyyy hh:mm:ss"
Selection.NumberFormat = "dd-mmm-yyyy hh:mm:ss"
Selection.NumberFormat = "ddd, dd/mm/yyyy hh:mm:ss"
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss"
Selection.NumberFormat = "ddd, dd/mm/yyyy"
Selection.NumberFormat = "dd/mm/yyyy"
Selection.NumberFormat = "ddd, ddmmmyyyy"
Selection.NumberFormat = "ddmmmyyyy"
Selection.NumberFormat = "ddd, ddmmmyyyy hh:mm:ss"
Selection.NumberFormat = "ddmmmyyyy hh:mm:ss"
Selection.NumberFormat = "yyyymmddhhmmss"
Selection.NumberFormat = "yyyymmdd-hhmmss"
Selection.NumberFormat = "yyyymmddhhmmss (ddd)"
Selection.NumberFormat = "yyyymmdd-hhmmss (ddd)"
Selection.NumberFormat = "yyyymmdd"
Selection.NumberFormat = "yyyymmdd (ddd)"
Selection.NumberFormat = "yyyy-mm-ddThh:mm:ss"
Selection.NumberFormat = "yyyymmddThhmmss"
It seems that it is currently, at least, no possible to enter code such as "Selection.NumberFormat = "yyyyWwwd"", etc, into Excel. The additional "formats" that I would like to gain access to are shown below.
I have also written a VB6ProSP6 demo program to generate dates and times according to a selection of the various ISO8601:2004 "formats" some of which can't (currently) be simulated using any of the Excel "Format" statements or the "Format Cell | Date, Time or Custom" dialog options. The formats which are inaccessible in Excel, unless one writes a function such as the inbuilt "WeekDay(cell,2)" for the ISO8601 week commencement day of Monday = 1 thru Sunday = 7, are as follows and it is these that I would like to "simulate":
- yyyyWww & yyyy-Www; for example, 2010W28 & 2010-W28
- ISO8601:2000(E) |
AnnexB | Examples | B.1 Dates | Calendar week
- yyyyWwwD & yyyy-Www-D; for example, 2010W287 & 2010-W28-7
- ISO8601:2000(E) | AnnexB | Examples | B.1 Dates | Week date
- yyyyddd & yyyy-ddd; for example, 2010200 & 2010-200
- ISO8601:2000(E) | AnnexB | Examples | B.1 Dates | Ordinal date
On 18/07/2010 07:10, Tex Texin wrote:
If you go into number formats and choose custom, you can enter yyyy-mm-dd or yyyymmdd.
If you need a macro to accomplish that, turn on macro recording and format a cell as above. Then save it. that should get you going.
You can probably also set that in a function, but I haven’t tried and haven’t time right now.
If you can’t get it to work as you like, come back and clarify what you need and I’ll give it a go later.
Has anyone come across an Excel macro (ideally compatible with all versions from Excel 2000 onwards) for formatting cells for the ISO8601 "Day in Year" format (ie "YYYYDDD" and "YYYY-DDD")? The year ("YYYY") component can be obtained using the Excel function "YEAR(cell)" but I can't find an existing Excel builtin function for the "day-in-year" ("DDD") component.
Paul Myers, JP(NSW), BSc(UNSW), MACS
PO Box 7007 Karabar NSW 2620 AUSTRALIA
Ph/Fx: 02 6299 2392 / +61 2 6299 2392
Mobile: 041 629 9239 / +61 41 629 9239
"The only thing we have to fear is fear itself"
- Franklin D. Roosevelt's First Inaugural Address, 04 March 1933
FEAR - "False Evidence Appearing Real"
See my favourite quotes by clicking here