| Start |
|---|
| Allow full column references without penalty It's easier to implement some UDFs on the worksheet if full column references can be passed in as parameters. However, due to the explicit nature of coding, any loop involving these ranges may be processing hundreds of thousands of cells that are completely empty. This reduces your VBA project (and workbook) to a frozen mess while unnecessary non-values are processed. Looping through a worksheet's cells is one of the slowest methods of accomplishing a task but sometimes it is unavoidable. Cutting the work performed down to what is actually required makes perfect sense. The solution is to truncate the full column or full row references to the Worksheet.UsedRange property (opens new window) with the Intersect method (opens new window). The following sample will loosely replicate a worksheet's native SUMIF function so the criteria_range will also be resized to suit the sum_range since each value in the sum_range must be accompanied by a value in the criteria_range. The Application.Caller (opens new window) for a UDF used on a worksheet is the cell in which it resides. The cell's .Parent (opens new window) property is the worksheet. This will be used to define the .UsedRange. In a Module code sheet: Syntax: While this is a fairly simplistic example, it adequately demonstrates passing in two full column references (1,048,576 rows each) but only processing 15 rows of data and criteria. Linked official MSDN documentation of individual methods and properties courtesy of Microsoft™. |
UDF - Hello World
To obtain :
|
Count Unique values in Range Collections (opens new window) Syntax**Function functionName(argumentVariable As dataType, argumentVariable2 As dataType, Optional argumentVariable3 As dataType) As functionReturnDataType** **functionName = theVariableOrValueBeingReturned** **End Function** RemarksA User Defined Function (aka UDF) refers to a task specific function that has been created by the user. It can be called as a worksheet function (ex: It can be created by :
|
Read Article
https://develop.horje.com/learn/1434/reference