Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

More Excel Function Techniques You

Need to Know
This is a guest article from Yoav Ezer. If you want to guest post on this blog, check out the
guidelines here.
The IF() function is one of Excel‟s super functions. It is a fundamental building-block of
Excel formulas. You will find it present in almost any complex formula. There is a lot more
power in Excel formulas conditions than just the basic IF() function, though.

Here are 7 conditional techniques that can help you create even more robust and useful
Excel formulas:

1. Nested If Functions
This is the most basic type of „complex‟ if() function. You can use an additional if function to
create a more complex condition within your Excel formula.

For instance:

=IF(A1>10,IF(A1<20,"In range"))

The function above would test whether cell A1 contains a value that‟s between 10 and 20.
Only if both conditions are satisfied then the formula returns the value “In range”.

It is possible to use several levels of IF() function nesting. For example:

=IF(A1>10,IF(A1<20,IF(B2="HAS AMMO","FIRE!!!!")))

The formula above tests that A1 contains a number that is within range and that B2 holds
the status „HAS AMMO‟ and only if those three conditions are satisfied, it returns a value of
“FIRE!”.

2. Logical-Boolean Functions
Nesting is powerful but it is complicated and often results in a formula that is difficult to
read or change. A much better way to create complex conditions is to use Excel‟s Boolean
functions.

The AND() function will return true if all its parameters are true conditions.

So, the formula…

=IF(AND(A1>10,A1<20), "In range")


1
Page

Compiled By Hasan Jawaid


Will also check if cell A1 is between 10 and 20 pluse, it is much easier to understand (and to
write) then the nested formula above.

The following formula…

=IF(AND(A1>10,A2<20,B1="HAS AMMO"),"FIRE!")

Is ten times easier to write/read then the corresponding nested IF() above

Another extremely useful Boolean function is the OR() function.

The formula…

=IF(OR(A1="CAT IS AWAY",A1="CAT IS BUSY"),"THE MICE PLAY")

Will return „THE MICE PLAY‟ if A1 equals either „cat is away‟ or „cat is busy‟.

3. Countif, SumIf, Averageif, etc.


This group of functions allows you to apply a range function such as SUM(), COUNT() OR
AVERAGE() only to rows that meet a specific condition.

For instance, you can sum or count all the sales that were made during the year 2001 as
shown below:

It goes without saying that these conditional functions are very useful.

4. Countifs, SumIfs, Averageifs, etc.


The COUNTIFS() and SUMIFS() function (and the rest of the multiple conditions aggregate
functions) were introduced in Excel 2007.
2

These functions enable us to apply an aggregation function to a subset of rows where those
Page

rows meet several conditions.

Compiled By Hasan Jawaid


For instance, we can use the SUMIFS() function to sum all the sales that were made in the
January of 2001, with a single function…

5. If and Array Formulas


Array formulas might be the most advanced of the formula techniques and while we can‟t
hope to cover the topic of array formulas in this article, it is important to mention that
combining the IF() function with array formulas is a powerful tool.

In Excel versions prior to 2007, the formula AVERAGEIF() did not exist. So, if for example,
you wished to average a range of numbers without including Zeros in the calculation, you
needed to rely on an array formula:

Array formulas can also be used to mimic the working of countifs(), sumifs() and the rest of
the xxxxxifs() functions, that simply did not exist in Excel versions before 2007.
3

They can also be used to implement new functions that does not exist such as MAXIF() and
Page

MINIF().

Compiled By Hasan Jawaid


For a more in depth discussion of array formulas, look here.
6. IFError() function
A close relative of the IF() function is the IFERROR() function. It allows you return a valid
value in case a formula returns an error. For instance, if you have a formula that might
cause a division by zero error, you can use the IFERROR() function to catch this event and
return a valid value, as shown below:

Note: It is
better to use the IF() function to avoid an error then to use the ISERROR() function to catch
an error. It is both faster (in terms of CPU) and better programming practice. So the same
result we achieved with the ISERROR() function above can be achieved with an IF() function
as shown here:

But there are cases when you cannot pretest the formula parameters and in those cases the
ISERROR() function can come in handy.

7. Information functions
Distant relatives of the IF() function are the information functions. This group includes
several functions that give you information about the type of the value contained in a cell (if
4
Page

Compiled By Hasan Jawaid


it‟s a string, a number, an odd number or an even number), if a cell is empty or if it
contains an N/A value and more.

These functions, when used in conjunction with the IF() function can be pretty handy, for
example, they allow you to easily check whether a cell is empty:

Summary

Our examples in this article only scratch the surface, we would encourage you to
experiment more into what you can do. These seven simple functions hide a great deal of
power and utility.

They are the building blocks of some very useful macros. We hope we have inspired you to
put them to use in your own projects!

5
Page

Compiled By Hasan Jawaid


Working with Dates

So we have the date 14-Jun-2010 in cell A1. If we want to find the date of the first day of
the month, all we have to do is create a date with the same Year and Month as A1 and
change the day to 1. Simple, right?

What can we do if we want to find the first day of the previous month?

We already know how to find the first day (just put 1 in the DAY argument), so for the
previous month we just subtract 1 from the MONTH. The YEAR will stay the same, and there
you go.

Note: This works even for dates in January because Excel‟s Date function can handle 0 and
negative numbers correctly
To find the last day of the month is a little bit trickier. The solution is not straight forward as
before because each month has a different number of days. This is where understanding
how DATE is stored makes the difference.
6
Page

Compiled By Hasan Jawaid


We know that DATE is actually a number, so why not subtract 1 from the first day of the
next month?

We use the same Year as A1, Add 1 to the month, and change the day to 1, this will give us
the first day of the following month (1-Jul-2010), now we subtract 1 (remember, the DATE
is stored as a number) and we get the last day of the previous month.

How to Create your own Timeline with Microsoft


Excel
It‟s quite easy to create a basic timeline in Microsoft excel using a Timeline Template.
Download a sample Timeline template for Ms-Excel and follow the steps mentioned
below:
1. Open the template for editing and you will see a sample timeline with rows of data as
shown below:

7
Page

Compiled By Hasan Jawaid


Do not delete the existing rows as this may mess up the timeline sequence.

2. To edit or add custom events in the timeline, double click a row with the Yellow
Background and enter a sentence or event in the function field as shown below:

3. To edit the dates, right click the X axis and select “Format axis”. Next, enter the starting
date and the duration of units which you want to appear in the timeline.

4. Once you are done with setting up the dates, you may want to delete or move the events
to a specific year. Just select the cursor placed over the year icon in the Timeline preview
and you can move the events to a specific date unit.
8
Page

Compiled By Hasan Jawaid


5. To delete an event from the timeline, first delete the year and then the event. Next,
move all the other events up and then modify the data series to match with the events in
the column that are not included in the graph.

Once the timeline is ready, use a screen capture utility or hit Windows Print screen to
capture the screen and save the timeline as an image file. More information on creating
timelines with Ms-Excel.
Online Tools to Create Interactive Timelines
There are web based tools to create timelines but they are not as impressive as Microsoft
Excel because you can not customize the Timeline with colors, fonts and images. You can
try Free Timeline and Timeline Maker to create horizontal and vertical timelines. But
none of them appear as appealing as Ms-excel mentioned above.
TimeRime is another web tool which can be used to create flash based timelines in
minutes. The timeline can include images, texts, dates and it‟s the best option because once
the timeline is complete you can make it public and let anyone in the world view it. (also
read: How to create pie charts and venn diagrams online)

9
Page

Compiled By Hasan Jawaid


Matrix Inverse Function (MINVERSE)

As you have noticed that there are three 2×2 matrices and one 3×3 matrix, we will be finding out
inverse of the matrices through Excel inherent function rather than applying old-school method for
evaluating matrix inverse which is;

Inverse (A)= |A| Matrix (Adj [A])


You must have been familiar with the evaluation process, it becomes so complex and tedious to
manage. But we will be using MINVERSE function which will yield inverse of matrix instantly.
The basic syntax of the function is;

=MINVERSE(array)
Where array could be the data range or values entered in the form of array. We will be writing
formula in the first matrix in Inverse column.
=MINVERSE(A2:B3)
Where A2:B3 is the range of matrix data in Matrix field. Select the first matrix in Inverse field
i.e E2:F3.and write a formula as mentioned above.
10
Page

Compiled By Hasan Jawaid


Now press Ctrl+Shift+Enter on keyboard to let Excel know that we are dealing with array. It will
enclosed formula in parenthesis { =MINVERSE(A2:B3) }, as shown in the screenshot below.

Apply the formula by copying it and pasting it in other cells after selecting cells contain in other
matrix.

For 3×3 matrix we will again write down the formula, select the cells contain in matrix and formula
will go like this;

{ =MINVERSE(A14:C16) }
It yields the result of matrix inverse in selected cells, as shown in the screenshot below.

11
Page

Compiled By Hasan Jawaid


You can also check out previously reviewed Matrix operation Function Evaluating Matrix
Determinant (MDETERM) and other
functions; DOLLAR, SUMPRODUCT, SUMIF, COUNTIF, VLOOKUP, HLOOKUP,PMT, and LEN.

As an example of how a two-row, two-column matrix is calculated, suppose that the range A1:B2

contains the letters a, b, c, and d that represent any four numbers. The following table shows the

inverse of the matrix A1:B2.

Column A Column B

Row 1 d/(a*d-b*c) b/(b*c-a*d)

Row 2 c/(b*c-a*d) a/(a*d-b*c)

MINVERSE is calculated with an accuracy of approximately 16 digits, which may lead to a small

numeric error when the cancellation is not complete.

Some square matrices cannot be inverted and will return the #NUM! error value with MINVERSE. The

determinant for a noninvertable matrix is 0.


12

Example
Page

Compiled By Hasan Jawaid


EXAMPLE 1

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

1. Select the example in this article.

IMPORTANT Do not select the row or column headers.

Selecting an example from Help

2. Press CTRL+C.

3. In Excel, create a blank workbook or worksheet.

4. In the worksheet, select cell A1, and press CTRL+V.

IMPORTANT For the example to work properly, you must paste it into cell A1 of the worksheet.

5. To switch between viewing the results and viewing the formulas that return the results, press CTRL+`

(grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas

button.

A B

1 Data Data

2 4 -1

3 2 0

4 Formula Formula

5 =MINVERSE(A2:B3)

The formula in the example must be entered as an array formula. After copying the example to a
13

NOTE

blank worksheet, select the range A5:B6 starting with the formula cell. Press F2, and then press
Page

CTRL+SHIFT+ENTER. If the formula is not entered as an array formula, the single result is 0.

Compiled By Hasan Jawaid


EXAMPLE 2

The example may be easier to understand if you copy it to a blank worksheet.

How do I copy an example?

1. Select the example in this article.

IMPORTANT Do not select the row or column headers.

Selecting an example from Help

2. Press CTRL+C.

3. In Excel, create a blank workbook or worksheet.

4. In the worksheet, select cell A1, and press CTRL+V.

IMPORTANT For the example to work properly, you must paste it into cell A1 of the worksheet.

5. To switch between viewing the results and viewing the formulas that return the results, press CTRL+`

(grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas

button.

A B C

1 Data Data Data

2 1 2 1

3 3 4 -1

4 0 2 0

5 Formula Formula Formula

6 =MINVERSE(A2:C4)
14
Page

Compiled By Hasan Jawaid


NOTE The formula in the example must be entered as an array formula. After copying the example to a

blank worksheet, select the range A6:C8 starting with the formula cell. Press F2, and then press

CTRL+SHIFT+ENTER. If the formula is not entered as an array formula, the single result is 0.25.

Tip Use the INDEX function to access individual elements from the inverse matrix.

CHOOSE Function

For using this function exclusively you can also add word as values, an example is shown in the
screenshot below.

Using SUMPRODUCT Function


Excel SUMPRODUCT is one of the most used function. Because of it’s versatility, it can be used in
numerous ways. This function can handle array in a simple way, giving novices an option to use
array without comprehending the structure of it. It can manipulate up to 25-30 arrays, requires list of
array as argument; =SUMPRODUCT(array1, array2….). So you just need to specify range of array
in your worksheet. Primarily it is used for adding and then multiply the values stored in array. This
post will be putting some light on how to use this function in your spreadsheet.
Launch Excel 2010 and open a spreadsheet on which you want to apply SUMPRODUCT function.
For Instance, we have included a spreadsheet, containing records of Item & it’s respective price and
number of products to be delivered, and corresponding charges as; Items, Delivery,
Price, and Delivery Charges,as shown in the screenshot below.
15
Page

Compiled By Hasan Jawaid


Now we want to find out Total amount to be paid by the customers, including all the charges from
every city. For evaluating total amount, old-school method can be used, but it would be hectic to
write one. We will be using SUMPRODUCT function to evaluate the Total amount. We will start off
with including row label Total Amount beneath the table and in it’s adjacent cell we will be writing the
formula.

For calculating total amount we will write formula like this;

=SUMPRODUCT(C2:D11,E2:F11)
The first argument in the formula is C2:D11, this marks up the location of array1, which
contains Items & Delivery field, and the second parameter E2:F11 which contains items price and
delivery charges.
For example we need this sort of calculation for desired result; (56*100)+(2*100) and so on. It will
evaluate by, multiplying number of items sold with it’s respective Prices and Delivery with its Delivery
charges, as shown in the screenshot below.
16
Page

Compiled By Hasan Jawaid


Now we will be changing the value into currency value. From Home tab, under Number group, click
drop-down button, and click Currency.

17
Page

Compiled By Hasan Jawaid


18
Page

Compiled By Hasan Jawaid


HLOOKUP Function In Excel
Excel HLOOKUP function can be used when you are dealing with huge datasheet and need to look
up the values of the specific record. HLOOKUP stands for Horizontal lookup, used to find specific
data from the datasheet. Unlike VLOOKUP function, it looks for the values horizontally which
enables the user to extract a complete record. This post elaborates how & where you can use
HLOOKUP function.
Launch Excel 2010, and open a datasheet on which you want to apply HLOOKUP function.

For instance, we have included student grading sheet containing courses name fields and a field
containing name of the students as shown in the screenshot below.

Now we want to apply HLOOKUP function, for this we will start off with adding a new row in which
we will be looking up for the data of specific student. Suppose we are dealing with a gigantic
datasheet containing loads of student records, in this scenario if we want to look up for the record of
student Jack, then we will add the row label by the name of student and start pulling the marks he
secured from each each Course column; e.g. Software Engg, Se II etc.

19
Page

Compiled By Hasan Jawaid


Now we will be writing formula adjacent to Jack cell, Unlike VLOOKUP function, it looks for data
horizontally, The syntax of HLOOKUP function is;
=HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup] )
The first parameter of the formula lookup_value defines the value of the number which we will be
looking in the specified row. We need to lookup the mark in the newly created cell. The next
parameter,table_array defines the table array we will be referring to in our case it will be portion of
datasheet containing courses labels, with corresponding data (courses with marks secured ).
row_index_numdefines, which row we want to extract values to show, in our case it is the second
row that contain respective course marks. [range_lookup] lets you to choose an option either
TRUE(approximately matching of values) or FALSE (Exact matching of values).
We will write this function in the cell adjacent to Jack cell, it will go like this;
=HLOOKUP(B1,$B$1:$H$11,2,FALSE)
In the formula parameters, B1 is cell of column Software Engg which contain marks secured by the
student Jack, B1:H11 is the array of the data containing all courses labels and their respective
values (use absolute referencing with $ sign), 2 in the formula means that values from second row
will appear, and FALSE defines that we need exact match.
As you can see in the screen shot below that, the formula will yield 18 the marks secured
by Jack inSoftware Engg course (at B1 location)
20
Page

Compiled By Hasan Jawaid


Now if you want to know marks secured by Jack in each course, just drag the plus sign across the
row, as shown in the screenshot below.

There is another interesting way in which HLOOKUP function can be used, in this we will be creating
exclusive table for student jack and looking up for the marks, by specifying course name, as shown
in the screenshot below.
21
Page

Compiled By Hasan Jawaid


The whole formula is the same except the first parameter (A44), actually it is referring to the cell in
which will write the course name. Now when we will specify course name, corresponding marks
value will automatically appear.

Now apply it over the table and make an exclusive one for student Jack.
22
Page

Compiled By Hasan Jawaid


23
Page

Compiled By Hasan Jawaid


VLOOKUP Function In Excel 2010
Excel VLOOKUP function can be used when you need to look up the values in the specific table and
check it against the other data fields for comparison purpose. VLOOKUP stands for Vertical lookup,
used to find specific data from the datasheet. By creating a sample table generally referred as
lookup table you can extract info from it and compare it with the desired field to yield required
results. This post elaborates where you can use VLOOKUP function.
Launch Excel 2010, and open a datasheet on which you want to apply VLOOKUP function.
For instance, we have included a student grading datasheet, containing fields; Name, Course, and
Marks.

Now we will add new column Grade, which will contain grades secured by the students. Now for this,
we will be using VLOOKUP function for looking up values from other table that contains sample data
for grades.
Create two new columns containing marks range (sorted in any order) and corresponding grades.
you don’t need to create them in a new worksheet, you can place anywhere in the existing datasheet
24

as we just want to get values from it.


Page

Compiled By Hasan Jawaid


Now in the Grade first row, we will write VLOOKUP function. The syntax of this function is
VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup] )
The first parameter of the formula lookup_value defines the value of the number which we will be
looking in the newly created table. We need to lookup the value 80 (Marks field) in the newly created
table. The next parameter, table_array defines the table we will be referring to in our case it will be
newly created table, containing ranges of marks and grades. col_index_num defines data from
which column we want to extract values to show, in our case it is the second column that contain
grades range. [range_lookup] lets you to choose an option either TRUE(approximately matching of
values) or FALSE (Exact matching of values).
We will write this function in Grade first row, it will go like this;
=VLOOKUP(C2,$F$3:$G$8,2,TRUE)
In the formula parameters, C2 is cell of column Marks which contain marks secured by
students, F3:G8 is the location of the newly created table, containing ranges of marks and grades
(use absolute referencing with $ sign), 2 in the formula means that values from second column will
appear, and TRUE defines thatwe need approximately match as we have included ranges not exact
values.
After evaluating formula, it will show grade A in Grade column as shown in the screen shot below.
25
Page

Compiled By Hasan Jawaid


Now apply this function over the whole Grade column, drag the plus sign towards the end
of Gradecolumn to apply it over, as show in the screen shot below.

26

Now we also want to calculate the prize money for each student. for instance, we assume the
Page

following criteria.

Compiled By Hasan Jawaid


For grade A $1000

For grade B+ $700

For grade B &600

For grade C+ $250

For grade D N/A

The criteria defined contains the exact value, so we will be making a small change in the parameters
of the function. we will be choosing FALSE from [range_lookup] instead of TRUE as we want to
show the exact match.

D2 contains the grade secured by students, so it will check the value in Grade column against the
newly created columns, containing prize money criteria, as shown in the screenshot below.

Now apply the function in Prize Money column to view the prize money won by each student. Now
as you can see in the screenshot below that by using VLOOKUP function it is easier to look up
specific values for populating new fields by connecting different columns.
27
Page

Compiled By Hasan Jawaid


28
Page

Compiled By Hasan Jawaid


SUMSQ function
Excel SUMSQ is very useful function when you need to return the sum of squares of the specified
values in spreadsheet, rather than going for manual evaluation. It would be more useful by providing
it with location of cells as function arguments where the data is residing, but you can directly put in
values as argument to get them evaluated.
Launch Excel 2010 spreadsheet on which you want to apply SUMSQ function. For instance, we
have included a spreadsheet containing fields, S.No, Series 1, Series 2 and Sum of SQRT.

Now we will find out the square of both values in Series 1 and Series 2 field and show sum of the
resultant values. For this we will be using SUMSQ function.
The syntax of SUMSQ function is;

=SUMSQ(number1, number2…)
We will be putting location of cells as arguments in the function and write this function in first row
of SUM Of SQRT field as;
=SUMSQ(B2,C2)
The function arguments B2 and C2 are the location of cells. It will yield SUM of values after taking
square of both values, as shown in the screenshot below.
29
Page

Compiled By Hasan Jawaid


Drag the plus sign at the end of the cell towards the end of column to apply it over the Sum Of
SQRTfield.

If you want, you can evaluate SUMSQ function exclusively by putting in values directly.

Now for using this function by giving direct value and location of cells simultaneously, you will need
to write it as;

=SUMSQ(location_of_cell, number)
30
Page

Compiled By Hasan Jawaid


31
Page

Compiled By Hasan Jawaid


How to convert a numeric value into English words in Excel
View products that this article applies to.

This article was previously published under Q213360

On This Page

Expand all | Collapse all

SUMMARY

This article contains sample Microsoft Visual Basic for Applications functions that you can use to convert a numeric value in a

Microsoft Excel worksheet cell into its equivalent in English words.

Back to the top

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes,

but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that

you are familiar with the programming language that is being demonstrated and with the tools that are used to create and

to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However,

they will not modify these examples to provide added functionality or construct procedures to meet your specific

requirements.

Back to the top

How to create the sample function Called SpellNumber

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.

5. Option Explicit
6. 'Main Function
7. Function SpellNumber(ByVal MyNumber)
8. Dim Dollars, Cents, Temp
9. Dim DecimalPlace, Count
32

10. ReDim Place(9) As String


Page

11. Place(2) = " Thousand "

Compiled By Hasan Jawaid


12. Place(3) = " Million "
13. Place(4) = " Billion "
14. Place(5) = " Trillion "
15. ' String representation of amount.
16. MyNumber = Trim(Str(MyNumber))
17. ' Position of decimal place 0 if none.
18. DecimalPlace = InStr(MyNumber, ".")
19. ' Convert cents and set MyNumber to dollar amount.
20. If DecimalPlace > 0 Then
21. Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
22. "00", 2))
23. MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
24. End If
25. Count = 1
26. Do While MyNumber <> ""
27. Temp = GetHundreds(Right(MyNumber, 3))
28. If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
29. If Len(MyNumber) > 3 Then
30. MyNumber = Left(MyNumber, Len(MyNumber) - 3)
31. Else
32. MyNumber = ""
33. End If
34. Count = Count + 1
35. Loop
36. Select Case Dollars
37. Case ""
38. Dollars = "No Dollars"
39. Case "One"
40. Dollars = "One Dollar"
41. Case Else
42. Dollars = Dollars & " Dollars"
43. End Select
44. Select Case Cents
33

45. Case ""


46. Cents = " and No Cents"
Page

47. Case "One"

Compiled By Hasan Jawaid


48. Cents = " and One Cent"
49. Case Else
50. Cents = " and " & Cents & " Cents"
51. End Select
52. SpellNumber = Dollars & Cents
53. End Function
54.
55. ' Converts a number from 100-999 into text
56. Function GetHundreds(ByVal MyNumber)
57. Dim Result As String
58. If Val(MyNumber) = 0 Then Exit Function
59. MyNumber = Right("000" & MyNumber, 3)
60. ' Convert the hundreds place.
61. If Mid(MyNumber, 1, 1) <> "0" Then
62. Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
63. End If
64. ' Convert the tens and ones place.
65. If Mid(MyNumber, 2, 1) <> "0" Then
66. Result = Result & GetTens(Mid(MyNumber, 2))
67. Else
68. Result = Result & GetDigit(Mid(MyNumber, 3))
69. End If
70. GetHundreds = Result
71. End Function
72.
73. ' Converts a number from 10 to 99 into text.
74. Function GetTens(TensText)
75. Dim Result As String
76. Result = "" ' Null out the temporary function value.
77. If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
78. Select Case Val(TensText)
79. Case 10: Result = "Ten"
80. Case 11: Result = "Eleven"
34

81. Case 12: Result = "Twelve"


82. Case 13: Result = "Thirteen"
Page

83. Case 14: Result = "Fourteen"

Compiled By Hasan Jawaid


84. Case 15: Result = "Fifteen"
85. Case 16: Result = "Sixteen"
86. Case 17: Result = "Seventeen"
87. Case 18: Result = "Eighteen"
88. Case 19: Result = "Nineteen"
89. Case Else
90. End Select
91. Else ' If value between 20-99...
92. Select Case Val(Left(TensText, 1))
93. Case 2: Result = "Twenty "
94. Case 3: Result = "Thirty "
95. Case 4: Result = "Forty "
96. Case 5: Result = "Fifty "
97. Case 6: Result = "Sixty "
98. Case 7: Result = "Seventy "
99. Case 8: Result = "Eighty "
100. Case 9: Result = "Ninety "
101. Case Else
102. End Select
103. Result = Result & GetDigit _
104. (Right(TensText, 1)) ' Retrieve ones place.
105. End If
106. GetTens = Result
107. End Function
108.
109. ' Converts a number from 1 to 9 into text.
110. Function GetDigit(Digit)
111. Select Case Val(Digit)
112. Case 1: GetDigit = "One"
113. Case 2: GetDigit = "Two"
114. Case 3: GetDigit = "Three"
115. Case 4: GetDigit = "Four"
116. Case 5: GetDigit = "Five"
35

117. Case 6: GetDigit = "Six"


118. Case 7: GetDigit = "Seven"
Page

119. Case 8: GetDigit = "Eight"

Compiled By Hasan Jawaid


120. Case 9: GetDigit = "Nine"
121. Case Else: GetDigit = ""
122. End Select
123. End Function

Back to the top

How to use the SpellNumber sample function

To use the sample functions to change a number to written text, use one of the methods demonstrated in the following

examples:

Back to the top

Method 1: Direct Entry

You can change 32.50 into "Thirty Two Dollars and Fifty Cents" by entering the following formula into a cell:

=SpellNumber(32.50)

Back to the top

Method 2: Cell reference

You can refer to other cells in the workbook. For example, enter the number 32.50 into cell A1, and type the following

formula into another cell:

=SpellNumber(A1)

Back to the top

Method 3: Paste Function or Insert Function

To enter a custom function into a worksheet, you can use Paste Function in Excel 2000, or you can useInsert Function in

Excel 2002 and in Excel 2003.

Excel 2000

To use Paste Function, follow these steps:

1. Select the cell that you want.

2. Click Paste Function on the Standard toolbar.


36

3. Under Function category, click User Defined.


Page

4. Under Function name, click SpellNumber, and then click OK.

Compiled By Hasan Jawaid


5. Enter the number or cell reference that you want, and then click OK.

Excel 2002 and Excel 2003

To use Insert Function, follow these steps:

1. Select the cell that you want.

2. Click Insert Function on the Standard toolbar.

3. Under Or select a category, click User Defined.

4. In the Select a function list, click SpellNumber, and then click OK.

5. Enter the number or cell reference that you want, and then click OK.

Back to the top

APPLIES TO

Back to the top

Keywords: kbdtacode kbhowto kbprogramming KB213360

Back to the top

37
Page

Compiled By Hasan Jawaid

You might also like