Excel VBA: Format Currency with Two Decimal Places – 3 Methods

Entering the Code in the Visual Basic Editor

  • Go to the Developer tab.
  • Click Visual Basic.

  • Click Insert and select Module.

Enter the code and press F5 to run it.


Method 1 – Using the VBA Format Function to Format a Number as Currency with Two Decimal Places

The syntax of the Format function is:

Format(expression, [format], [firstdayofweek],[firstweekofyear])

expression- any valid expression. You can insert a number or Range object as the argument.
format- a valid number format (predefined or user-defined)

To format the list of random numbers below as currency:


1. 1 Using Currency as the Number Format

  • Copy the following VBA code:
Sub FormatCurrencyWithTwoDecimalPlaces()
Range("C6") = Format(Range("B6"), "Currency")
Range("C7") = Format(Range("B7"), "Currency")
Range("C8") = Format(Range("B8"), "Currency")
Range("C9") = Format(Range("B9"), "Currency")
End Sub

Excel VBA Format Currency to Two Decimals

  • Press F5 to run the code.

This is the output.

Excel VBA Format Currency to Two Decimals

The currency formatted numbers have 2 decimal places (defined by default).

To check it:

  • Select a currency-formatted cell.
  • Press Ctrl + 1.
  • See the value in “Decimal places”.

Excel VBA Format Currency to Two Decimals


1.2 Apply a Custom Number Format

Use the following custom format code:

$#,###.00

Enter the following code in the Visual Basic Editor.

Sub FormatCurrencyWithTwoDecimalPlaces()
Range("C6") = Format(Range("B6"), "$#,###.00")
Range("C7") = Format(Range("B7"), "$#,###.00")
Range("C8") = Format(Range("B8"), "$#,###.00")
Range("C9") = Format(Range("B9"), "$#,###.00")
End Sub
Excel VBA Format Currency to Two Decimals

Read More: Excel VBA: Number Format with No Decimal Places


Method 2 – Format a Number as Currency Using the Range.NumberFormat Property in Excel VBA

The syntax of this property is:

expression.NumberFormat = “pre-defined or user-defined number format”

  • Enter the code:
Sub FormatCurrencyWithTwoDecimalPlaces()
Range("B6").NumberFormat = "$#,###.00"
Range("B7").NumberFormat = "$#,###.00"
Range("B8").NumberFormat = "£#,###.00 "
Range("B9").NumberFormat = "£#,###.00"
End Sub

Excel VBA Format Currency to Two Decimals

  • Run the code.

This is the output.

Excel VBA Format Currency to Two Decimals

The British Pound (£) and the Dollar ($) signs were used in the custom format code.

Read More: How to Use Excel VBA to Format Number in Decimal Places


Method 3 – Using theVBA FormatCurrency Function to Convert a Number to Currency Format in Excel

The syntax of the function is:

FormatCurrency(Expression, [ NumDigitsAfterDecimal, [ IncludeLeadingDigit, [ UseParensForNegativeNumbers, [GroupDigits]]]])

expression- any valid expression. You can insert a number or Range object as the argument.

NumDigitsAfterDecimal- specifies the decimal places to display in the currency formatted number. It is optional. If you leave it blank, the default value (2 decimal places) is displayed. This value is set by the regional settings.

  • Use the code:
Sub FormatCurrencyWithTwoDecimalPlaces()
Range("C6") = FormatCurrency(Range("B6"), 2)
Range("C7") = FormatCurrency(Range("B7"), 2)
Range("C8") = FormatCurrency(Range("B8"))
Range("C9") = FormatCurrency(Range("B9"))
End Sub

Excel VBA Format Currency to Two Decimals

  • Press F5 to run the code.

Excel VBA Format Currency to Two Decimals


Notes

To change the regional settings:

  • Go to the Control panel.
  • Click Change date, time, or number formats.

Excel VBA Format Currency to Two Decimals

  • Select Additional settings.

  • In the Numbers tab, the “No of digits after decimal” displays 2.

  • In the Currency tab, the default currency symbol is dollar $.

 


Download Practice Workbook

Download the practice workbook.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Al Arafat Siddique
Al Arafat Siddique

Al Arafat Siddique, BSc, Naval Architecture and Marine Engineering, Bangladesh University of Engineering and Technology, has worked on the ExcelDemy project for two years. He has written over 85+ articles for ExcelDemy. Currently, he is working as a software developer. He is leading a team of six members to develop Microsoft Office Add-ins, extending Office applications to interact with office documents. Other assigned projects to his team include creating AI-based products and online conversion tools using the latest... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo