Vous êtes sur la page 1sur 23

MS Office Tuts - Kamaraj Mani Page 1 of 23

Share Report Abuse Next Blog» Create Blog Sign In

MS Office Tuts - Kamaraj Mani


Home

Friday, September 24, 2010

User Defined Functions (UDF)


About Me Polls

Kamaraj Mani Poll


Chennai, What should be my
Tamilnadu, India next post?
I, Kamaraj mani, c MS-Word
d
e
f
g
blessed with a c MS-Excel
d
e
f
g
lovely mother
born in the city of temples – MS Excel allows us to create our own UDFs (user-defined functions). Using the help of VBA c MS-Powerpoint
d
e
f
g
Madurai. I do shake hands (Visual Basic Application), we can make formulas only once and use them any number of times c MS-Access
d
e
f
g
with Mr. Paint and Ms. Brush in our Excel Sheets and workbooks. These UDFs can be applied just like any other built-in c MS-Outlook
d
e
f
g
sometimes. Sincerity, hard functions, which are already available in MS-Excel.
work, perseverance,
Vote See results
innovation and creativity are
In this Post, we are going to see how to create a simple UDF.
my friends and I prefer 1 voter
playing with rows and You have to be signed in
columns and this is what Visual Basic Editor: to vote.
made me to create a blog
(http://msofficetuts.blogspot.c To create the UDF, we need to call up the Visual Basic Editor.
om). As an MS Office
explorer, I want to contribute 1. In MS-Excel 2003, It is located in the Tools > Macros Menu.
more through this blog to Search
quench your thirst to learn all 2. In MS-Excel 2007, to locate it, we have to follow the following steps.
MS office application and to Search
establish how passionate I  Step 1: Enable the Developer Tab. powered by
am, to explore MS Office.
 Click the Microsoft Office Button, and then click Excel
View my complete profile
Options.
Recent Posts
Blog Archive User Defined Functions (UDF)
MS Excel allows us
to create our own
▼ 2010 (4) UDFs...

▼ September (2)
Multi-Level Numbering - Excel
User Defined In this Tutorial, I
Functions
(UDF)

Multi-Level am going to explain you how...


Numbering - How to use Advance Filter
Applies to MS-
Excel Excel 2003, MS-
Excel 2007In this...
► August (2)
Powered By : Blogger Plugins

Picture A: Excel Options Subscribe To

 In the categories pane, click Popular and select Show


Developer tab in the ribbon.

Followers

Follow
with Google Friend Connect

Followers (5)

Picture B: Developer Ribbon

Already a member?Sign in
 Click OK to close the Option dialog box.

 Step 2: Open Visual Basic Editor


Label Cloud
 Click the Developer item on the main ribbon and then click
Visual Basic item in the code panel.

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 2 of 23

Shortcut to open VBE

excel (4) excel


2003 (3) excel 2007
(3) Advanced Filter (1) Filter
(1) MS-Office (1) Skill Level 3
VBE will open with three windows inside the VBE environment. They are, (1) User defined fuctions (1)
VBE (1) combined formula (1)
excel formula (1) formula (1)
1. The Project Window (1), hlookup (1) match (1)
2. The Code Window (2), and range_lookup (1) tutorial (1)
vlookup (1)
3. The Properties Window (3).

Picture C: Visual Basic Editor

We can resize the windows by left-clicking where the resize icons, holding and moving sideways
or up and down.

User Defined Function

To create a UDF, we need to insert a module.

Click Insert > Module.

The VBE creates a New Module (Module1) inside the project (See Project window).

Picture D: Insert Module

Note: If we record any macro, the macro will be stored inside the module only.

Every custom function (UDF) begins with the key word ‘Function’ followed by the name of the
function and parentheses. It ends with the key word ‘End Function’.

VBE will automatically insert this End Function key word, once we hit the enter key after typing
the function, function name and the parentheses.

Now we are going to create a UDF to compute 194C Contract TDS.

When we make single payment to the Contractor, if the contract payment is Rs.30000 or more
and the type of the contract is Individual/HUF, 1% on the Contract Payment will be deducted as
TDS (if the contractor is other than individual/HUF, then 2% on the contract payment will be
deducted as TDS). If the single payment is less then Rs. 30000, no TDS will be deducted on the
contract payment.

Type the code inside the code windows as given in the below picture.

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 3 of 23

Picture E: Code Window

Explanation:

1. ContractTDS is the name of the function


2. Amount & Contractor are variables
3. First step, we need to identify the type of the contractor. If the user enters the type of the
contractor as ‘others’, our function will pick the TDS Rate as 2%. Otherwise, it will pick
1% as rate of TDS.
4. Second step, we need to identify whether the single payment amount is less than 30000
or not. If the user enters amount as 30000 or more, system will apply TDS rate on the
Payment amount. Otherwise, it will consider ContractTDS as Nil.
5. Finally, the function will return the result.

How to insert UDF in Excel Worksheet:

1. Close the VBE window. Go to the excel and select any worksheet.
2. Select B1 and type ‘others’
3. Select B2 and type ‘35000’
4. Enter our formula as given in the below picture.

Picture F: Apply UDF in the Worksheet

5. Function will return ‘700’ as TDS. (i.e. 2% on 35000, because amount is not less
than 30000 and the contractor type is others)
6. Change your inputs and see the result.

Posted by Kamaraj Mani N at 5:11 AM 1 comments


Labels: excel, excel 2003, excel 2007, Skill Level 3, User defined fuctions, VBE

Did this help you?

Wednesday, September 1, 2010

Multi-Level Numbering - Excel

In this Tutorial, I am going to explain you how to insert multi-level numbering


using Formulas in Excel. Click here to download the exercise spreadsheet.

Details available in the Excel sheet (KM_Ex3_Multi-level_Numbering.xls) are -

Column A Chapter Numbers 24 Chapters


Column B Titles 247 Titles
Column C Count 247 Titles

Before we start, just estimate how much time it will take to number the 247 titles
along with Chapter numbers like 1-1, 1-2….27-1, 27-2….27-n. I guarantee that we

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 4 of 23

can number them within 15 seconds.

Is that possible?

Let us try it out..

Step 1:

1. Insert a column between A & B;


2. Enter the cell value as ‘1’ in Cell B3. i.e. we are starting with Chapter 1.
3. Enter the following formula in Cell B4

=IF(ISBLANK(A4),B3,B3+1)

Picture A: If fuction

Formula Explanation:

1. ISBLANK(A4): This formula checks whether any value/formula exists or not


in Cell A4. If any value is there, the function returns the message "FALSE"
(i.e. the cell has some value in it). If no value/formula exists, it
returns “TRUE”.
2. IF(ISBLANK(A4),B3,B3+1):

 Formula Structure: =(logical_test,value_if_true,value_if_false)

 Condition (logical_test): We need to check whether A4 is blank


or not. We are using ISBLANK(A4) as a logical test. We will get
either TRUE or FALSE as a result.

 True Value (Value_if_true): If the ISBLANK(A4) returns TRUE,


we are going to retain the same chapter number. Hence we put B3
as Value_if_true.

 False Value (Value_if_false): If the ISBLANK(A4) returns FALSE,


next chapter is started. we need to add 1 with the previous chapter
number. Hence we need to put B3+1 as Value_if_false.

Step 2:

1. Double click the Fill Handle Fill Handle: The small black square in
the lower-right corner of the selection. When you point to the Fill Handle, the
pointer changes to a black cross

Picture B: Fill Handle

2. All the remaining 245 rows will be filled with corresponding Chapter Numbers
as shown in below picture.

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 5 of 23

Picture C: Chapter Numbers

3. Chapter number for all the 24 chapters are ready now.

Step 3:

Now we are going to insert title numbers.

1. Insert a new column between B & C


2. Enter the cell value as ‘1’ in Cell C3. i.e. we are starting with Title number 1.
3. Enter the following formula in Cell C4

=IF(ISBLANK(A4),C3+1,1)

Picture D: IF Function

Formula Explanation:

1. ISBLANK(A4): This formula checks whether any value/formula exists or not


in Cell A4. If any value is there, the function returns the message "FALSE"
(i.e. the cell has some value in it). If no value/formula exists, it
returns “TRUE”.
2. IF(ISBLANK(A4),C3+1,1):

 Condition (logical_test): We need to check whether A4 is blank


or not. We will get either TRUE or FALSE as a result.

 True Value (Value_if_true): If the ISBLANK(A4) returns TRUE,


we are still in the same chapter and need to add 1 with the
previous title number to get Number for next title. Hence, we need
to put C3+1 as Value_if_true.

 False Value (Value_if_false): If the ISBLANK(A4) returns FALSE,


Next Chapter is started. We need to put ‘1’ as first title number for
that chapter. Hence, put 1 as Value_if_false.

3. Double click the Fill Handle


4. All the remaining 245 rows will be filled with corresponding Title Numbers.
Check C17, it is started with 1 as a title number for next chapter (Chapter 2).

Picture E: Title Numbers

Step 4:

1. Insert a new column between C & D


2. Select D3, click insert function icon

3. Insert Function dialog will pop up

 Select Text from the Select a category drop down box.

 Select CONCATENATE from the Select Function list box

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 6 of 23

 Press OK

4. Enter the field with the values as given in the below image and press OK

5. Double click the Fill Handle


6. Column D represents the multi-level numbering for the titles.
7. Now select Column B,C & D.
8. Press Ctrl+C.
9. Right click on the Cell B1, Select Paste Special.
10. Paste Special Dialog will appear. Now select Value under Paste group and
Click OK

11. Remove Column B & C

Result will be as given in the below image

Try yourself. Sure, It wont take more than 15 Secs.

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 7 of 23

Posted by Kamaraj Mani N at 7:38 AM 0 comments


Labels: excel, excel 2003, excel 2007
Did this help you?

Thursday, August 19, 2010

How to use Advance Filter

Applies to MS-Excel 2003, MS-Excel 2007

In this session, we are going to discuss how to use Advance Filter when the Auto
filter fails to give the desired results.

Picture 1: Custom AutoFilter

Custom Auto filter (Picture 1) will help us to filter data with the maximum of TWO
filter criteria only. When we have more than TWO criteria, we have to use the
Advanced Filter.

Before applying the Advance Filter what are all necessary information we should
require?

1. Data Table
2. Criteria Table

1. DATA Table:

1. The FIRST ROW of the database should have HEADINGS.


2. There SHOULD NOT be any fully BLANK ROWS within the Database.
3. LAST COLUMN and LAST ROW should be BLANK. (Why is this necessary?
While applying Advance Filter, system will automatically select the LIST
RANGE by default)

Picture 2: Database Sample

2. CRITERIA Table

I have already mentioned that to filter the data with more than two criteria, we are
using the Advanced Filter option. In Picture 2, we are having FOUR different
products; out of these we are going to select THREE products as Filter criteria to
filter the data.

How to define Criteria Table?

1. Select a blank cell in an unused part of the worksheet.


2. Give Criteria Title (It should be same as your database FIELD TITLE.
Example: here the database field title is PRODUCT. The same title only we
have to use as Criteria title. It will help the system to identify the field on
which it has to apply the advance filter)
3. Mention all the THREE product’s names in the subsequent rows.

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 8 of 23

Sample of Criteria Table is given below:

Picture 3: Criteria Table

Both the basic things are ready.Now, how to apply the Advance Filter?

Select Data>Filter>Advanced Filter

Picture 4: Advanced Filter Dialog Box

MS-Excel, by default, will ask us to give the following two inputs:

1. List Range
2. Criteria Range

1. LIST RANGE:

To fix the List range:

1. By selecting the Advance Filter itself, System will select the List range
automatically.

Picture 5: List Range

2. If List range is not picked up automatically or if you want to restrict the data

range, then you have to click Collapse Dialog button to choose the List
Range.
3. Select the Database Table where you want to apply filter.

2. Criteria Range

To fix the Criteria range:

1. Click: Criteria Range Collapse Dialog button to choose the Criteria


Range

Picture 6: Advanced Filter - Criteria Range

2. Select the Criteria table what you have created

3. Now Press Expand Button.

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 9 of 23

Picture 7: Advanced Filter - After basic Inputs

RESULT:

We can get the result in two ways:

1. Filter the list, in-place


2. Copy to another location

1. Filter the List, in-place

1. It is a default option.
2. Now, if we press OK Button, Advanced Filter will filter the data and show the
result (Row index will be turned in BLUE colour) in the Database Table itself.

Picture 8: Filtered Data

(See the row index 4,5,7,8 and 9 are not visible now)

2. Copy to another Location

1. Under Action, we have to select “Copy to another Location” option button


2. Now the “Copy to collapse dialog box” (as shown below) will be activated.

Picture 9: Copy to dialog

3. Here, we have to give the cell reference where the filtered result should be
printed.
4. Press OK

How to remove the filter:

Select DATA>FILTER>SHOW ALL

Please create the following table and try the exercise to get a clear idea about the
Advance filter and feel the difference

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 10 of 23

Picture 10: Data Table

Exercise 1:

Picture 11: Exercise Number 1

Exercise 2:

Picture 12: Exercise Number 2

Exercise 3:

Picture 13: Exercise Number 3

Exercise 4:

Picture 14: Exercise Number 4

Posted by Kamaraj Mani N at 1:35 AM 3 comments


Labels: Advanced Filter, excel, excel 2003, excel 2007, Filter

Did this help you?

Tuesday, August 17, 2010

VLookup - New Usage


Can it be possible….? Friends, just go through the following case and tell me is
there any possibility available to solve the issue with the help of VLOOKUP function.

A dealer wants to give a festival offer to his customers. He announces the following
discounts.

Units Product A Product B Product C

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 11 of 23

Pick the appropriate discount rates for the following cases with the help of
VLOOKUP function:

1. Z orders 100 units of product B


2. X orders 600 units of Product C.
3. Y orders 2500 units of product A.

Without looking at the solution try these cases... if you are unable to find the
solution then read further.

VLOOKUP Function

Recall the syntax of VLOOKUP function. i.e., =vlookup


(Lookup_value,table_array,col_index,range_lookup)

Here, we are giving FOUR Input parameters. Let us concentrate only on the fourth
parameter now to solve this case.

Range_lookup

While using Vlookup function, we are used to assign FALSE (0) as Range_Lookup.
What will be the result if I assign TRUE (1) as Range_Lookup?

 FALSE (0) as Range_Lookup: VLOOKUP will find the exact match, and if it
is not found, it will return an error value (#N/A).

 TRUE (1) as Range_Lookup: This function will return the exact match,
and if the same is unavailable, it will return the approximate match. In
other words, if VLOOKUP can't find lookup_value, it uses the largest value
that is less than or equal to lookup_value.

To solve the above said cases we have to use TRUE (1) as Range_lookup.

To illustrate, I am going to take the 3rd case - Y orders 2500 units of product A. (to
explain the first 2 cases, we need some assistance from other function to get the
result. We can get the result for the first 2 cases with the help of combined
functions only.)

CASE 3:

Syntax is =vlookup(2500,A1:B4,2,1)

The function will return 10% as result as “2500” will not exactly match with the
database. So, the function will look for the next highest value that is less than
2500.

To check this formula, you can try with some other units (say 499 units, 950 units
or with exact values 0, 500 and 1000)

OTHER CASES

In the previous case, we have used 2 as column index to find the discount rate for
2500 units of Product A. we know that the details of Product A are available under
column 2. How can we assist the system to find the column index automatically
instead of feeding the column index manually?

MATCH Function

This function will return the relative position of an item from the selected area (i.e
row or column)

Syntax: =match(lookup_value,lookup_array,match_type)

Let us now find the Column index of Product B

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 12 of 23

=match(“Product B”,A1:D1,0)

The function will return 3 as result.

COMBINED FUNCTION

Now we are going to solve the first 2 cases. For that we have to combine VLOOKUP
function and MATCH function to get the desired result.

CASE 1:

Here we have two inputs i.e ITEM and ORDER QTY. First, we need to find the
discount rate for Product B when the ordering quantity is 100 units.

Instead of giving column index manually, here we have inserted MATCH function to
get the column index. (To test this function, change the item name as Product A or
Product C)

Now, Try the rest (You already know how to use) to get the net value of the
ordered quantity.

REMEMBER

 To get the accurate result from the VLOOKUP function, lookup_values


(i.e. in this example “Units” column) should be in ascending order.

 If it is not so, the function may not find the largest value that is lower
than the lookup value.

Posted by Kamaraj Mani N at 4:25 AM 1 comments


Labels: combined formula, excel, excel formula, formula, hlookup, match, MS-Office,
range_lookup, tutorial, vlookup
Did this help you?

Home

Subscribe to: Posts (Atom)

Recent Comments

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 13 of 23

PAVAN KUMAR wrote...


Hey Kamraj...Simply superb.. Thanks for sharing

Karthik wrote...
Proud of u Mani.

Kamaraj Mani N wrote...


@ Harish: I agree.. Excel 2007 has many advance features... This Tuts is mainly for the Lower version users (Excel 2003)...

Harish wrote...
Ur step by step explanation is good. but now this option is readily available in Excel 2007, where you can choose/filter for multiple items at one go.

Juned wrote...
Very nice Kamaraj...Keep it up :)

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 14 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 15 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 16 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 17 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 18 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 19 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 20 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 21 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 22 of 23

http://msofficetuts.blogspot.com/ 30.09.10
MS Office Tuts - Kamaraj Mani Page 23 of 23

http://msofficetuts.blogspot.com/ 30.09.10

Vous aimerez peut-être aussi