Convert Numbers to Malaysian Ringgit and Sen in Excel VBA
Question details
The user wants to convert numerical values into text words formatted as Malaysian currency (Ringgit and Sen) using an Excel VBA macro.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Generating financial reports, invoices, or receipts where the total numeric amount needs to be spelled out explicitly in Malaysian Ringgit and Sen.
- Observed behavior
- Standard spreadsheet functions do not spell out numbers in Malaysian currency natively, requiring a custom VBA script to separate the whole numbers and decimals and convert them into Ringgit and Sen text.
Ensure your workbook is saved as an Excel Macro-Enabled Workbook (*.xlsm) and that you have enabled macros in your security settings.
Create a Custom SpellNumber Function in VBA
Use the Visual Basic Editor to insert a custom macro that translates numerical values into written words using Ringgit and Sen.
By modifying a standard SpellNumber VBA script, you can easily adapt it for Malaysian currency. This custom function will handle whole numbers as Ringgit and decimal values as Sen automatically.
Press Alt+F11 on your keyboard to open the Visual Basic Editor (VBE) in Excel.
Click on 'Insert' in the top menu and select 'Module'. This ensures the code is globally accessible across the workbook.
Paste your standard SpellNumber VBA code into the blank module window. Use the Find and Replace tool (Ctrl+H) within the editor to replace all instances of 'Dollar' or 'Dollars' with 'Ringgit', and 'Cent' or 'Cents' with 'Sen'.
Go to File > Save As, and choose 'Excel Macro-Enabled Workbook (*.xlsm)' from the file type dropdown menu to preserve your new macro.
Return to your worksheet, click on a blank cell, and type `=SpellNumber(A1)` (replace A1 with the cell containing your numeric value) to see the converted text.

Troubleshoot Formula Errors
Resolve common issues if the custom SpellNumber function returns a #NAME? or #VALUE! error.
Run VBA Macros Seamlessly in WPS Spreadsheet
WPS Spreadsheet offers excellent compatibility with Excel VBA macros. You can create, edit, and run your custom Ringgit and Sen conversion scripts directly within WPS Office without altering the original code.
- 1. Enable Macros: Open your .xlsm file in WPS Spreadsheet and click 'Enable Macros' if prompted by the security warning.
- 2. Access the VBA Editor: Navigate to the Developer tab and click 'Visual Basic', or press Alt+F11 to view and edit your conversion code.
- 3. Use the Function: Type `=SpellNumber(A1)` in any cell just as you would in Microsoft Excel to convert numeric values to Malaysian currency.

Frequently Asked Questions
Why does my custom VBA function return a #NAME? error?
This usually occurs if the macro was pasted into a Worksheet module instead of a Standard Module, if macros are disabled in your Trust Center settings, or if the function name was misspelled in the cell.
Can I adapt this VBA code for other currencies besides Ringgit?
Yes. You can open the VBA Editor and replace the text strings 'Ringgit' and 'Sen' with 'Euros' and 'Cents', or 'Pounds' and 'Pence', depending on your specific currency requirements.
Will this macro work if I email the spreadsheet to a colleague?
Yes, as long as you save the file as a Macro-Enabled Workbook (.xlsm) and your colleague enables macros when they open the file on their computer.
Does this function support millions and billions?
Yes, a standard SpellNumber VBA function is designed to support large numbers including thousands, millions, and larger amounts, provided the code includes the logic for those specific tiers.




