headermask image

Business Tools Blog

Convert a Number with Currency in Excel into a Spelled/Written Word for use in Mail Merge

It makes me crazy when I have to complete a mail merge and the numbers that are so nicely formated in Excel turn into unformatted numbers in Word’s mail merge.   This can be solved by using the TEXT function, for example, if I wanted 1000 to show up like $1,000.00 in my mail merge document, I would use the below formula (where cell A1has the number that I want to be formatted as currency in my mail merge document.)

=TEXT(A1,”$#,##0.00″)

The next challenge is when I want to proceed the $1,000.00 with the words “One Thousand Dollars and No Cents”.  I can make this happen using the following formula (where cell A1has the number that you want to be formatted as text in your mail merge document)

=ConvertCurrencyToEnglish(A1)

But not so fast.  That formula only works after you have added this macro: http://support.microsoft.com/kb/210586

  1. Start Microsoft Excel.
  2. Press ALT+F11 to start the Visual Basic Editor.
  3. On the Insert menu, click Module.
  4. Type the following code into the module sheet.
Function ConvertCurrencyToEnglish (ByVal MyNumber)
   Dim Temp
   Dim Dollars, Cents
   Dim DecimalPlace, Count

   ReDim Place(9) As String
   Place(2) = " Thousand "
   Place(3) = " Million "
   Place(4) = " Billion "
   Place(5) = " Trillion "

   ' Convert MyNumber to a string, trimming extra spaces.
   MyNumber = Trim(Str(MyNumber))

   ' Find decimal place.
   DecimalPlace = InStr(MyNumber, ".")

   ' If we find decimal place...
   If DecimalPlace > 0 Then
      ' Convert cents
      Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
      Cents = ConvertTens(Temp)

      ' Strip off cents from remainder to convert.
      MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
   End If

   Count = 1
   Do While MyNumber <> ""
      ' Convert last 3 digits of MyNumber to English dollars.
      Temp = ConvertHundreds(Right(MyNumber, 3))
      If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
      If Len(MyNumber) > 3 Then
         ' Remove last 3 converted digits from MyNumber.
         MyNumber = Left(MyNumber, Len(MyNumber) - 3)
      Else
         MyNumber = ""
      End If
      Count = Count + 1
   Loop

   ' Clean up dollars.
   Select Case Dollars
      Case ""
         Dollars = "No Dollars"
      Case "One"
         Dollars = "One Dollar"
      Case Else
         Dollars = Dollars & " Dollars"
   End Select

   ' Clean up cents.
   Select Case Cents
      Case ""
         Cents = " And No Cents"
      Case "One"
         Cents = " And One Cent"
      Case Else
         Cents = " And " & Cents & " Cents"
   End Select

   ConvertCurrencyToEnglish = Dollars & Cents
End Function

Private Function ConvertHundreds (ByVal MyNumber)
   Dim Result As String

   ' Exit if there is nothing to convert.
   If Val(MyNumber) = 0 Then Exit Function

   ' Append leading zeros to number.
   MyNumber = Right("000" & MyNumber, 3)

   ' Do we have a hundreds place digit to convert?
   If Left(MyNumber, 1) <> "0" Then
      Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
   End If

   ' Do we have a tens place digit to convert?
   If Mid(MyNumber, 2, 1) <> "0" Then
      Result = Result & ConvertTens(Mid(MyNumber, 2))
   Else
      ' If not, then convert the ones place digit.
      Result = Result & ConvertDigit(Mid(MyNumber, 3))
   End If

   ConvertHundreds = Trim(Result)
End Function

Private Function ConvertTens (ByVal MyTens)
   Dim Result As String

   ' Is value between 10 and 19?
   If Val(Left(MyTens, 1)) = 1 Then
      Select Case Val(MyTens)
         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
      ' .. otherwise it's between 20 and 99.
      Select Case Val(Left(MyTens, 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

      ' Convert ones place digit.
      Result = Result & ConvertDigit(Right(MyTens, 1))
   End If

   ConvertTens = Result
End Function

Private Function ConvertDigit (ByVal MyDigit)
   Select Case Val(MyDigit)
      Case 1: ConvertDigit = "One"
      Case 2: ConvertDigit = "Two"
      Case 3: ConvertDigit = "Three"
      Case 4: ConvertDigit = "Four"
      Case 5: ConvertDigit = "Five"
      Case 6: ConvertDigit = "Six"
      Case 7: ConvertDigit = "Seven"
      Case 8: ConvertDigit = "Eight"
      Case 9: ConvertDigit = "Nine"
      Case Else: ConvertDigit = ""
   End Select
End Function

If you liked my post, feel free to subscribe to my rss feeds

3 Comments so far (Add 1 more)

  1. Avoiding these kind of food as well as by using an
    eating plan capsule just like Phen375 you need to will no longer find being hungry a challenge.
    May possibly become used to reading relating to the lines in
    products, especially the ones that are advertised online.

    Instead of serving your public with a decent
    quality body fat burners or body fat loss tool, Acai berry-Noni Burners has a third-rate product that’s certainly riding the coattails of the nutritionally packed berry market.

    1. Phen375 Ingredients on July 14th, 2013 at 11:59 am
  2. It’s very simple to find out any matter on web as compared to books, as I found this paragraph at this site.

    2. area converter on April 28th, 2013 at 8:42 am
  3. Excellent goods from you, man. I have understand your stuff previous
    to and you’re just extremely great. I really like what you have acquired here, really like what you are stating and the way in which you say it. You make it entertaining and you still take care of to keep it sensible. I can not wait to read far more from you. This is really a tremendous website.

    3. quick loans on February 23rd, 2013 at 2:38 pm

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*