access vba training - date formats functions
Microsoft Office Training verified by visa - mastercard securecode about microsoft training company london ukadd this page to your favourites/bookmarksAdd to favourites
view a printable version of this pagePrintable version
email this page to somebodyEmail this page
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft VBA Training and help » access vba training - Date formats in Functions

access vba training - Date formats in Functions

The UK's most regular instructor-led training courses.
Training information: access vba training · Excel london

resolvedResolved · Low Priority · Version Standard

Date formats in Functions

James has attended:
Excel VBA course

by - delegate James [7 posts] (2007 Dec 5 Wed, 14:55) replyReply

I am using the following excel formula in one of my cells:

="USD Balance as at "&DAY(TODAY()) & " " &MONTH(TODAY()) & " " &YEAR(TODAY())

Is it possible to create a function that will fill in the month in text form rather than number?

ie the above creates 5 12 2007 and I want it to show 5 December 2007

RE: Date formats in Functions

by - trainer Carlos gold contributer[479 posts] (2007 Dec 10 Mon, 12:51) replyReply

Hi James

All you need to do is use the TEXT function on the Month's number value as seen in the reworked formula below. The use of "mmmm" produces the full month while "mmm" only produces the abreviation:

="USD Balance as at "&DAY(TODAY()) & " " & TEXT(MONTH(TODAY()),"mmmm") & " " &YEAR(TODAY())


Hope this helps

Carlos

RE: Date formats in Functions

by - delegate James [7 posts] (2007 Dec 10 Mon, 14:19) replyReply

Hi Carlos,

I tried the above formula but it only seems to return "January" as the month value. This seems to be an excel bug as when I rewrote the formula as:

="USD Balance as at "&DAY(TODAY()) & " " & TEXT(MONTH(A1),"mmmm") & " " &YEAR(TODAY())

I tried several dates in A1 and the formula always returned the value "January"

Any ideas why?

James

RE: Date formats in Functions

by - trainer Carlos gold contributer[479 posts] (2007 Dec 10 Mon, 14:58) Edited on 2007 Dec 10 Mon, 14:59 replyReply

James

Yes I have an idea. The TEXT function does not work as I presented it. I didn't notice the problem because I've been messing with my computer and had the date on Jan 2008.

I then checked some books and they all say there is no way of changing the months value to Text.

So I created a Function that takes the date you specify ie Totay() and by checking the Month value retrurns a month's name.

The code is:

Public Function MonthText(MyDate As Date) As String

Dim Monthvalue As Byte

MonthValue = Month(MyDate)

Select Case MonthValue

Case 1
MonthText = "January"

Case 2
MonthText = "February"

Case 3
MonthText = "March"

Case 4
MonthText = "April"

Case 5
MonthText = "May"

Case 6
MonthText = "June"

Case 7
MonthText = "July"

Case 8
MonthText = "August"

Case 9
MonthText = "September"

Case 10
MonthText = "October"

Case 11
MonthText = "November"

Case 12
MonthText = "December"

End Select

End Function


Then your formula would read

="USD Balance as at "&DAY(TODAY()) & " " & MonthText(TODAY()) & " " &YEAR(TODAY())


This should solve your problem

Carlos

RE: Date formats in Functions

by - delegate James [7 posts] (2007 Dec 10 Mon, 15:28) replyReply

Thanks Carlos,

Trust Microsoft to make things difficult!!!

James


Related articles

· What Is Microsoft Excel VBA and How Can It Help You Work Smarter?
· Company Roles in Visual Basic Training
· Should You Send Managers To VBA Training?
· How To Find A Good VB For Access Trainer
· Visual Basic Returns To The Macintosh

Vba tip:

Empty The Clipboard with CutCopyMode

After each Copy/Paste operation in VBA, you should use the following line of code to empty the clipboard. This ensures that the computer memory doesn't overload:

ActiveSheet.Paste
Application.CutCopyMode = False

View all VBA hints and tips

Rate this page:
4.0/5 (3 votes cast)
Institute of IT Training - Accredited Training Provider Microsoft Certified Partner
microsoft office
Microsoft Office Specialist Authorised Testing Centre (MOS and MCAS)

Prodigy Platinum Learning Partner

Institute of IT Training - Accredited Training Provider Association of Computer Trainers Valid HTML 4.01 Transitional
Valid CSS Markup

secure online payments - visa - mastercard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Training by application Main information pages See also

Access courses
DreamWeaver courses
Excel courses
MS Project courses
Outlook courses
PowerPoint courses
VBA courses
Word courses
(more...)

Public scheduled courses
On-site training
Closed company courses

Microsoft Office training
Pricing and availability
Training schedule
Training venues

Access training
Dreamweaver training
Excel training
MS Project training
PowerPoint training

London Computer Training
Computer Training London

Microsoft Access training
Microsoft Excel training
Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training

Time Management Course London

Interested in Access training? Please see the following pages:
microsoft access courses · microsoft training access course
microsoft+access+training · access courses in london

Training Information

Training Articles

AddThis Social Bookmark Button What's this?
Add to Del.icio.us Add to Facebook Add to Digg Add to Reddit Add to Google Add to Yahoo Add to Diigo Add to Mr. Wong Add to Linkarena Add to Power Oldie Add to Folkd Add to Jumptags Add to Upchuckr Add to Simpy Add to StumbleUpon Add to Slashdot Add to Netscape Add to Furl Add to Spurl Add to Blinklist Add to Blogmarks Add to Technorati Add to Newsvine Add to Blinkbits Add to Ma.Gnolia Add to Smarking Add to Netvouz