IT Community - Software Programming, Web Development and Technical Support

How to Create an Excel Macro that converts currency in numbers into words?

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?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > VB.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 07-25-2007, 03:05 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 542
itbarota is on a distinguished road
Question How to Create an Excel Macro that converts currency in numbers into words?

How to Create an Excel Macro that converts currency in numbers into words?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 07-25-2007, 03:05 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN to kingmaker
Default Re: How to Create an Excel Macro that converts currency in numbers into words?

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 08-08-2007, 05:23 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 542
itbarota is on a distinguished road
Default Re: How to Create an Excel Macro that converts currency in numbers into words?

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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


All times are GMT -7. The time now is 10:06 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0