Excel VBA: Convert String to Currency
In this article
To convert a text string to a currency value in Excel VBA, use the CCur function: Dim amount As Currency: amount = CCur("1,234.56"). This works when the string is a recognizable number in your system's regional format. If the string contains symbols or non‑standard separators, clean it first with Replace and then apply CCur. The result is a Currency data type, which stores four decimal places and is ideal for money calculations.
What You'll Need
- Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer).
- Basic familiarity with the VBA editor (Alt+F11).
- A worksheet containing text values that look like numbers, or a way to create test strings.
Step-by-Step
- Open the VBA editor. Press Alt+F11 (or use Developer > Visual Basic). Insert a new module: Insert > Module.
- Write a simple conversion procedure. Start with a string that is already in a standard numeric format, for example
"1234.56". UseCCurto convert it:
Run it with F5. The message box should show 1234.56. If it shows an error, the string is not recognized as a number in your regional settings.Sub ConvertStringToCurrency() Dim textValue As String Dim currencyValue As Currency textValue = "1234.56" currencyValue = CCur(textValue) MsgBox currencyValue End Sub - Handle strings with currency symbols or thousands separators.
CCurdoes not accept symbols like $, €, or commas used as thousands separators in all locales. Remove them first:
This works for many cases, but be careful: in some European locales the comma is the decimal separator, so removing all commas would break the number. Adjust the replacements to match your regional format.textValue = "$1,234.56" textValue = Replace(textValue, "$", "") textValue = Replace(textValue, ",", "") currencyValue = CCur(textValue) - Use
Valas a fallback for mixed strings. If the string contains extra text (e.g., "USD 1234.56"),Valextracts the leading numeric part:currencyValue = CCur(Val(textValue)). However,Valstops at the first non‑numeric character, so it may return 0 if the string starts with letters. Clean the string first or useMidto extract the numeric portion. - Convert a range of cells. To process many cells, loop through a range and write the results to another column:
This checks each cell withSub ConvertRange() Dim cell As Range For Each cell In Range("A1:A10") If IsNumeric(cell.Value) Then cell.Offset(0, 1).Value = CCur(cell.Value) Else cell.Offset(0, 1).Value = "Invalid" End If Next cell End SubIsNumericbefore converting, avoiding errors on blank or text cells. - Format the result as currency. The Currency data type stores the value, but the cell display depends on number formatting. Set the
NumberFormatproperty:
Adjust the format string to your local currency symbol and separator style.cell.Offset(0, 1).NumberFormat = "$#,##0.00" - Test with edge cases. Try strings like "0", "-45.67", "1,000", and "abc". Ensure your code handles negatives, zero, and invalid input gracefully (e.g., using
On Error Resume NextorIsNumericchecks).
Common Mistakes
- Assuming
CCurignores currency symbols. It does not; you must strip them first. - Using
CDblorCSnginstead ofCCur. Those return floating‑point types, which can introduce rounding errors in money calculations.CCuris designed for currency. - Forgetting regional settings. A string like "1,234.56" may be interpreted differently on a system where comma is the decimal separator. Always test on the target machine or use explicit parsing.
- Not checking for empty strings.
CCur("")raises a type mismatch error. UseIf Len(Trim(textValue)) > 0 Thenbefore converting. - Overlooking negative values in parentheses. Accounting formats sometimes show negatives as "(123.45)".
CCurwill not parse that; you need to detect and convert manually.
Tips
- Use
IsNumericto test if a string can be converted before callingCCur. It returns True for strings that look like numbers in the current locale. - For consistent behavior across locales, consider using
Application.WorksheetFunction.NumberValue(Excel 2013+) to parse with explicit decimal and thousands separators. - When writing converted values back to cells, set the cell's
NumberFormatto a currency format so the display matches the data type. - If you need to store the result as a string with currency formatting, use
Format(currencyValue, "Currency")or a custom format string. - Always validate input: trim spaces, remove non‑breaking spaces (Chr(160)), and handle multiple currency symbols if your data is messy.
Troubleshooting
If CCur throws a "Type mismatch" error, the string is not recognized as a number. Check for leading/trailing spaces, currency symbols, or letters. Use Trim and Replace to clean the string. If the error persists, test with a simple numeric string like "123" to confirm the function works in your environment. If the converted value is wrong (e.g., 1.234,56 becomes 1.234), your regional settings may use comma as decimal separator; adjust your cleaning logic accordingly. For ranges, ensure you are not trying to convert cells that contain formulas returning errors; check with IsError first. If the code runs but the cell shows a date or other format, set the NumberFormat explicitly. If you get an "Overflow" error, the number is too large for the Currency type (range roughly -922,337,203,685,477.5808 to 922,337,203,685,477.5807); use CDec for larger values, but note CDec is not a native data type and has its own limits.
Frequently Asked Questions
Can I convert a string with a currency symbol directly using CCur?
No, CCur does not accept currency symbols. Remove them with Replace before converting.
What is the difference between CCur and CDbl?
CCur returns a Currency data type with fixed‑point arithmetic and four decimal places, suitable for money. CDbl returns a Double floating‑point number, which can cause rounding errors in financial calculations.
How do I handle strings with thousands separators like "1,234.56"?
Remove the separators with Replace(text, ",", "") if your locale uses comma as thousands separator. If your locale uses comma as decimal separator, adjust accordingly.
Why does CCur("1,23") return 123 in some systems?
Because in locales where comma is the decimal separator, "1,23" is interpreted as 1.23, but if the system expects a period as decimal, it may treat the comma as a thousands separator and return 123. Always test with your regional settings.
Can I convert an entire column of text to currency in one go?
Yes, loop through the range and apply CCur to each cell after validating with IsNumeric. Write the results to adjacent cells or overwrite the original cells.
What if the string contains non‑breaking spaces?
Use Replace(text, Chr(160), "") to remove them before conversion.