Solved

Convert Date to French on button click

Posted on 2011-02-15
3
358 Views
Last Modified: 2012-05-11
Hi all, I have a range that points to a cell that contains a Date. The range is called Period_End_Date, I have a button that switches the language from English to French and vice versa. I need to be able to change the date format to French / English on the fly, can someone show me how to do that? My button code is below.
Public Sub LangGetSet(source As Integer)
 'scroll through Language sheet and check against ID passed in
    If source = 1 Then
        If language = "English" Then
            language = "French"
        'set date format of Period_End_Date to French (i.e. 20 Mai 2011)

        ElseIf language = "French" Then
            language = "English"
        'set date format of Period_End_Date to English (i.e 20 May 2011)
        End If
    End If
End Sub

Open in new window

0
Comment
Question by:boukaka
3 Comments
 
LVL 10

Expert Comment

by:cdebel
ID: 34902342
What do you mean by "On the fly"?  Without pressing the button?

You could trap a worksheet_change event, and check if the target correspond to your range.  If it correspond, then you need to know in which language you are displaying the date at the moment...
0
 
LVL 8

Accepted Solution

by:
wchh earned 500 total points
ID: 34902710
Try macro below
Public Sub LangGetSet(source As Integer)
 'scroll through Language sheet and check against ID passed in
    If source = 1 Then
        Range("A:A").Select 'Your date range
        If Selection.NumberFormat = "[$-809]d-mmm-yyyy;@" Then 'UK
            Selection.NumberFormat = "[$-40C]d-mmm-yyyy;@"  'French
        'set date format of Period_End_Date to French (i.e. 20 Mai 2011)
        Else
            Selection.NumberFormat = "[$-809]d-mmm-yyyy;@"
        'set date format of Period_End_Date to English (i.e 20 May 2011)
        End If
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:boukaka
ID: 34906436
Thanks so much, this works beautifully.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now