ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Execution speed for UDF (https://www.excelbanter.com/excel-programming/311727-execution-speed-udf.html)

Christian[_5_]

Execution speed for UDF
 
Hi NG,

I'm not a very advanced user of vba stuff.

I have a string that contains several field values. I made below UDF in the
VBE. The function allows me to enter 3 arguments to the function; cell with
the string to be examined, the delimter eg. "," or ";" and finally the field
number to output.

My function looks like this

Public Function SplitString(myCell As String, myDelimiter As String, myField
As Long) As Variant

Dim myArr As Variant
Dim myField2 As Long
myField2 = myField - 1 'vba assign 0 to the first field, more natural to
use 1 to represent the first field

myArr = VBA.Split(myCell, myDelimiter) 'adding inputcell content to
array and using split function to seperate each entry
SplitString = myArr(myField2) 'selecting the field to output

End Function

The function runs fairly slowly, can it be improve somehow?
Also in case there is no output the function currently return '0' in the
cell. Can the function be modified so that it returns nothing in case there
is nothing in the field?

Comments and suggestions are warmly welcome
- Chr




All times are GMT +1. The time now is 02:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com