Excel VBA formulas for Spreadsheet by Sharath Kumar Peechara - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Exercise 2: Custom Address Function

 

1. Create a UDF (User Defined Function)

To create this Function, execute the following steps

  1. Open Excel VBA (Altl + F11)
  2. Insert a New Module
  3. In the Project Explorer, double click on the Module
  4. Add the following code line:

img3.png

This Will Create A new UDF (User Defined Function) with name Emplycity,we Can use this As we Required. now type in Excel the function =Emplycity ,the UDF shows in small letter to differentiate itself from Standard Excel Formula

This Code lines will create function Emplycity ()

In Cell C1 Type

= Emplycity (A1)

img4.jpg

2. Use Excel Formulas (Lookup,Vlookup) Syntax

LOOKUP(lookup_value, array)

=LOOKUP(6983,A1:C10) ,

Excel will perform search to find out the city of the employeeID 6983

Syntax

VLOOKUP (lookup_value, table_array, col_index_num, [range_lookup])

=VLOOKUP(6983,A1:C10,3,TRUE)

Excel will perform search to find out the city of the employeeID 6983