Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

Automatically format cells to a selected currency

Latest post Wed, Mar 19 2008 3:45 AM by Nick Hodge. 1 replies.
  • Tue, Mar 18 2008 10:18 PM

    Automatically format cells to a selected currency

    I've created a spreedsheet that allows a users to choose a currency (Euro, US$, Aust$ etc) from a drop down list. This applies an exchange rate factor to a set of cells in the spreadsheet for a bunch of product prices. I would like the cells with the prices to use the correct currency format of the choosen currency. I have used =TEXT($E9*$G$8,$N$2) which does format the cell correctly BUT changes the format from a number to text which then makes subsequent calculations impossible.

    Any suggestions would be gratefully received.

    Filed under: ,
    • Post Points: 21
  • Wed, Mar 19 2008 3:45 AM In reply to

    • Nick Hodge
    • Top 10 Contributor
    • Joined on Sun, Dec 23 2007
    • Southampton
    • Posts 336
    • Points 5,771
    • MVP

    Re: Automatically format cells to a selected currency

    You could use a Worksheet_Change() event. The one below will take a text string in A1 and convert the format in B1 to whatever is set in A1 (There is no Case Else statement, so currently it must be one in the list, this can be expanded though)

    To place this, right click on the relevant sheet tab and select 'View Code', copy in here and then close the VBE and save.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("A1")) Is Nothing Then
        Select Case Target.Value
            Case Is = "AUD"
                Target.Offset(0, 1).NumberFormat = "_-[$$-C09]* #,##0.00_-;-[$$-C09]* #,##0.00_-;_-[$$-C09]* ""-""??_-;_-@_-"
            Case Is = "USD"
                Target.Offset(0, 1).NumberFormat = "_-[$$-409]* #,##0.00_ ;_-[$$-409]* -#,##0.00 ;_-[$$-409]* ""-""??_ ;_-@_ "
            Case Is = "YEN"
                Target.Offset(0, 1).NumberFormat = "_-[$¥-411]* #,##0.00_-;-[$¥-411]* #,##0.00_-;_-[$¥-411]* ""-""??_-;_-@_-"
            Case Is = "EUR"
                Target.Offset(0, 1).NumberFormat = "_-[$€-2] * #,##0.00_-;-[$€-2] * #,##0.00_-;_-[$€-2] * ""-""??_-;_-@_-"
            Case Is = "GBP"
                Target.Offset(0, 1).NumberFormat = "_-[$£-809]* #,##0.00_-;-[$£-809]* #,##0.00_-;_-[$£-809]* ""-""??_-;_-@_-"
        End Select
    End If
    End Sub

    Regards
    Nick Hodge
    Microsoft MVP, Excel
    Southampton, UK

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright Excel User Group and the relevant contributors, 2008. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.