• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sum with Tax/word

getco

New Member
Sum with Tax/word

Required formula for row A1:A5

Sum in A11 in figure & Tax/Words in A12.


A1 = 2

A2 = 3

A3 = 1

A4 = 10

A5 = 5


Ans.

A11 = 21 (In figure)

A12 = Twenty One. ( In Words)
 
Hi Getco,


For sum at A11, the formula would be:


=SUM(A1:A5) enter


Formula at A12( for converting number into formula) the formula would be:


=ConvertToWord(A11) ENTER


This is a user defined function (UDF), for which you need to copy and paste the below code in a standard module. To do this, press ALT+F11 from keyboard to bring the VB editor and insert a module (In VB editor, go to insert in the menu and click on module).


Function ConvertToWord(ByVal MyNumber)

Dim Result As String

If Val(MyNumber) = 0 Then Exit Function

MyNumber = Right("000" & MyNumber, 3)

' Convert the hundreds place.

If Mid(MyNumber, 1, 1) <> "0" Then

Result = Num(Mid(MyNumber, 1, 1)) & " Hundred "

End If


' Convert the tens and ones place.

If Mid(MyNumber, 2, 1) <> "0" Then

Result = Result & Get0ToTen(Mid(MyNumber, 2))

Else

Result = Result & Num(Mid(MyNumber, 3))

End If

ConvertToWord = Result

End Function


Function Get0ToTen(TensText)


Dim Result As String

Result = ""

If Val(Left(TensText, 1)) = 1 Then

Select Case Val(TensText)

Case 10: Result = "Ten"

Case 11: Result = "Eleven"

Case 12: Result = "Twelve"

Case 13: Result = "Thirteen"

Case 14: Result = "Fourteen"

Case 15: Result = "Fifteen"

Case 16: Result = "Sixteen"

Case 17: Result = "Seventeen"

Case 18: Result = "Eighteen"

Case 19: Result = "Nineteen"

Case Else

End Select

Else ' If value between 20-99...

Select Case Val(Left(TensText, 1))

Case 2: Result = "Twenty "

Case 3: Result = "Thirty "

Case 4: Result = "Forty "

Case 5: Result = "Fifty "

Case 6: Result = "Sixty "

Case 7: Result = "Seventy "

Case 8: Result = "Eighty "

Case 9: Result = "Ninety "

Case Else

End Select


Result = Result & Num _

(Right(TensText, 1)) ' Retrieve ones place.

End If

Get0ToTen = Result

End Function


Function Num(Digit)

Select Case Val(Digit)

Case 1: Num = "One"

Case 2: Num = "Two"

Case 3: Num = "Three"

Case 4: Num = "Four"

Case 5: Num = "Five"

Case 6: Num = "Six"

Case 7: Num = "Seven"

Case 8: Num = "Eight"

Case 9: Num = "Nine"

Case Else: Num = ""

End Select

End Function


Now go back to excel sheet and write the formula:


=ConvertToWord(A12) ENTER


Hope this helps...


Kaushik
 
Back
Top