Skip to content

Instantly share code, notes, and snippets.

@borekb

borekb/README.md Secret

Last active August 29, 2015 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borekb/4da4504081393ec536a0 to your computer and use it in GitHub Desktop.
Save borekb/4da4504081393ec536a0 to your computer and use it in GitHub Desktop.
Excel on-the-fly currency conversion in the status bar

Quickly converts numeric values to another currency and displays the result in the status bar. Based on this SO answer.

How to use:

  1. Open workbook
  2. Open VBA (Alt+F11)
  3. Select ThisWorkbook
  4. Right-click, View Code
  5. Paste code example, adjust ConvertMoney() and FormatMoney() functions to suit your needs (the example uses EUR -> CZK conversion with some additional formatting)
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
UpdateStatusBar (Target.value)
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
UpdateStatusBar (ActiveCell.value)
End Sub
Public Function UpdateStatusBar(value As Variant)
If IsNumeric(value) And value <> 0 Then
Application.StatusBar = FormatMoney(ConvertMoney(value))
Else
Application.StatusBar = False
End If
End Function
Public Function ConvertMoney(originalAmount As Variant)
ConvertMoney = originalAmount * 27
End Function
Public Function FormatMoney(amount As Variant)
roundedToThousands = Round(amount / 1000) * 1000
FormatMoney = (roundedToThousands / 1000) & " tis. CZK"
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment