+ Reply to Thread
Results 1 to 9 of 9

Very Simple Spell (Number to Words) 001 to 999 in VBA

  1. #1
    Registered User
    Join Date
    06-20-2019
    Location
    Qatar
    MS-Off Ver
    2019
    Posts
    33

    Very Simple Spell (Number to Words) 001 to 999 in VBA

    I have come across many spell number functions and have reviewed many VBA code available on the net.

    The core function that gets called repeatedly is the function that converts numbers from 001 to 999 as it is the core function for conversion under the English numeral system.
    I have seen that this core function is sometime unnecessarily split over sub-functions for converting one, tens, and 20s to 90s.

    I have developed the following simple VBA function that takes an input as number in a string format from “001” to “999” and returns the output as a string.
    The function uses the dash “-“ for numbers e.g. Forty-Two.

    The function is easily convertible to other languages.

    With your assistance, I am looking to further improve or simplifying the function, if possible.

    You may test the function like this:

    Debug.Print Do999("123")
    Debug.Print Do999("001")
    Debug.Print Do999("099")


    Thanks in advance for your contribution.


    Please Login or Register  to view this content.
    Last edited by MohsenAlyafei; 07-06-2019 at 07:54 AM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    • Why dash variable is not a String in the Dim statement ?

    • dash = "" is useless, you can remove it …

    • For string concatenation better is to use & operator instead of +

  3. #3
    Registered User
    Join Date
    06-20-2019
    Location
    Qatar
    MS-Off Ver
    2019
    Posts
    33

    Re: Very Simple Spell (Number to Words) 001 to 999 in VBA

    Quote Originally Posted by Marc L View Post
    Hi !

    • Why dash variable is not a String in the Dim statement ?

    • dash = "" is useless, you can remove it …

    • For string concatenation better is to use & operator instead of +
    Thanks Marc L. It is an old habit to to use the "" .

    I found the + to befaster than & when the string is already defined in a variable. Yes you are right. Thanks again.

  4. #4
    Registered User
    Join Date
    06-20-2019
    Location
    Qatar
    MS-Off Ver
    2019
    Posts
    33

    Re: Very Simple Spell (Number to Words) 001 to 999 in VBA

    Updated:

    Changed + to & and removed dash=""


    Please Login or Register  to view this content.
    Last edited by MohsenAlyafei; 07-06-2019 at 07:52 AM.

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Very Simple Spell (Number to Words) 001 to 999 in VBA

    Attached a User Defined Function adapted from Microsoft site.
    The function is called by 'NW'
    Two examples of cell formula use are illustrated in column 'A'

    By direct conversion in cell
    =NW(yournumber)
    By reference to another cell (C5) value formula in cell A5
    =NW(C5)
    Also can be called within VBA as a Worksheet function.

    torachan.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-20-2019
    Location
    Qatar
    MS-Off Ver
    2019
    Posts
    33

    Re: Very Simple Spell (Number to Words) 001 to 999 in VBA

    Quote Originally Posted by torachan View Post
    Attached a User Defined Function adapted from Microsoft site.
    The function is called by 'NW'
    Two examples of cell formula use are illustrated in column 'A'

    By direct conversion in cell

    By reference to another cell (C5) value formula in cell A5

    Also can be called within VBA as a Worksheet function.

    torachan.
    Thanks torachan. The Microsoft site function is too long for a simple task. It is simple for reading and learning.

  7. #7
    Registered User
    Join Date
    06-20-2019
    Location
    Qatar
    MS-Off Ver
    2019
    Posts
    33

    Re: Very Simple Spell (Number to Words) 001 to 999 in VBA

    Quote Originally Posted by torachan View Post
    Attached a User Defined Function adapted from Microsoft site.
    The function is called by 'NW'
    Two examples of cell formula use are illustrated in column 'A'

    By direct conversion in cell

    By reference to another cell (C5) value formula in cell A5

    Also can be called within VBA as a Worksheet function.

    torachan.
    I have downloaded the file and examined the code for converting numbers from 001 to 999 to words.
    There are 3 functions with losts of code and "Select Case" statement to do what a 5 statements do in the code I posted.

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Very Simple Spell (Number to Words) 001 to 999 in VBA

    @MohsenAlyafei, you are correct, your contribution is simple, reading & learning, however has very restrictive practical use.
    I only included my submission as it extended the possibilities to those that read this thread, illustrating what can be achieved with imagination.
    torachan.

  9. #9
    Registered User
    Join Date
    06-20-2019
    Location
    Qatar
    MS-Off Ver
    2019
    Posts
    33

    Re: Very Simple Spell (Number to Words) 001 to 999 in VBA

    Quote Originally Posted by torachan View Post
    @MohsenAlyafei, you are correct, your contribution is simple, reading & learning, however has very restrictive practical use.
    I only included my submission as it extended the possibilities to those that read this thread, illustrating what can be achieved with imagination.
    torachan.
    Thanks torachan.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Help to Modify the code to spell Numbers to words
    By tomohdi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2017, 10:53 AM
  2. [SOLVED] Spell Number VBA coding for Arabic words
    By arshad.99.ali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2016, 04:44 AM
  3. Spell Numbers to arabic Words
    By Amrbahgat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2014, 03:10 AM
  4. spell the numbers in words
    By israrkhan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-13-2014, 10:46 AM
  5. How does Excel spell out numbers in words ?
    By Kat in forum Excel General
    Replies: 1
    Last Post: 06-20-2006, 09:35 PM
  6. [SOLVED] Spell Checking - Special Words Not Picked Up by Excel
    By Hans Emilio in forum Excel General
    Replies: 4
    Last Post: 05-25-2005, 09:42 AM
  7. How do I spell numbers as words for writing checks in Excel?
    By Heather in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-11-2005, 05:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1