Jeff
Jeff

Reputation: 7

Custom date format in Excel VBA

I am trying to use the custom format to change the date from English to French. The custom code in regular Excel is [$-C0C]d mmmm;@ and yields the output as 20 juillet.

When using the following VBA code:

Format(Range("B2"), "[$-C0C]d mmmm;@")

The output is 20 July

[$-C0C] is supposed to be the code for French Canada

Upvotes: 0

Views: 2859

Answers (2)

Siddharth Rout
Siddharth Rout

Reputation: 149295

enter image description here

Try this

'~~> Replace Sheet1 below with the sheet code name of the cell which has date
Debug.Print Sheet1.Evaluate("text(B2, ""[$-C0C]d mmmm;@"")")

![enter image description here

Explanation: The format function can only take one of the pre-defined values as mentioned in Format Function (Visual Basic for Applications). Check out the section User-Defined Date/Time Formats (Format Function) And hence we use an alternative method.

Upvotes: 2

Pierre Delecto
Pierre Delecto

Reputation: 451

This did it for me:

Sheet1.Range("B2").NumberFormat = "[$-C0C]d mmmm;@"

Upvotes: 0

Related Questions