This is a discussion on How to Create an Excel Macro that converts currency in numbers into words? within the VB.NET Programming forums, part of the Software Development category; How to Create an Excel Macro that converts currency in numbers into words?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| How to Create an Excel Macro that converts currency in numbers into words? |
|
#2
| |||
| |||
| The following fuction can be used in an Excel macro page to convert a selection of values into words. Dim arrSingleDigit Dim arrTeen Dim arrTwoDigits Sub RSconvert() On Error Resume Next arrSingleDigit = Array("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") arrTeen = Array("eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty") arrTwoDigits = Array("10", "twenty ", "thirty ", "forty ", "fifty ", "sixty ", "seventy ", "eighty ", "ninety ", "Hundred") valdig = Trim("" + Selection.Text) If valdig = "" Or IsNumeric(valdig) = False Then Exit Sub valInDigits = valdig paisa = Int(valInDigits * 100 - Int(valInDigits) * 100) valInDigits = Int(valInDigits) If valInDigits > 0 Then If valInDigits > 999999999 Then MsgBox "Beyond Limit" Else msgtmp = convert(valInDigits) + " Rupees" If paisa <> 0 Then msgtmp = msgtmp + " and " + convert(paisa) + " Paisa" msgtmp = UCase(Left(msgtmp, 1)) + Right(msgtmp, Len(msgtmp) - 1) Selection.Text = msgtmp Exit Sub End If End If End Sub Private Function convert(valInDigits) Dim MSB Dim LSB If valInDigits > 0 And valInDigits < 10 Then converted = arrSingleDigit(valInDigits - 1) ElseIf valInDigits = 10 Then converted = "ten" ElseIf ((valInDigits > 10) And (valInDigits < 20)) Then converted = arrTeen(valInDigits Mod 10 - 1) ElseIf ((valInDigits >= 20) And (valInDigits <= 99)) Then MSB = valInDigits \ 10 converted = arrTwoDigits(MSB - 1) LSB = valInDigits Mod 10 If LSB > 0 Then converted = converted + convert(LSB) End If ElseIf ((valInDigits >= 100) And (valInDigits <= 999)) Then MSB = valInDigits \ 100 converted = convert(MSB) + " " + "hundred" LSB = valInDigits Mod 100 If LSB > 0 Then converted = converted + " " + convert(LSB) End If ElseIf ((valInDigits >= 999) And (valInDigits <= 99999)) Then MSB = valInDigits \ 1000 converted = convert(MSB) + " " + "thousand" LSB = valInDigits Mod 1000 If LSB > 0 Then converted = converted + " " + convert(LSB) End If ElseIf ((valInDigits >= 99999) And (valInDigits <= 9999999)) Then MSB = valInDigits \ 100000 converted = convert(MSB) + " " + "lakh" LSB = valInDigits Mod 100000 If LSB > 0 Then converted = converted + " " + convert(LSB) End If ElseIf ((valInDigits >= 9999999) And (valInDigits <= 999999999)) Then MSB = valInDigits \ 10000000 converted = convert(MSB) + " " + "crore" LSB = valInDigits Mod 10000000 If LSB > 0 Then converted = converted + " " + convert(LSB) End If End If convert = converted End Function |
|
#3
| |||
| |||
| Thanks but I would like to use it as an automized button that will convert all the rows that i select. Please give me the code for that. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Currency format | Kirubhananth | ASP and ASP.NET Programming | 2 | 03-13-2008 02:26 AM |
| what is flapjax and what are its benefits compared to javascript . How it converts fl | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 11-21-2007 01:55 AM |
| SQL reserved words | itbarota | Database Support | 1 | 09-26-2007 08:53 AM |
| Embedded Currency Conversion | Alkazar | HTML, CSS and Javascript Coding Techniques | 1 | 08-27-2007 06:57 AM |
| How to Create word Macro that converts currency in numbers into words? | itbarota | VB.NET Programming | 1 | 07-25-2007 03:03 AM |
Our Partners |