'------------------------- UDF that helps to extract nth string out of
'If "n" is missing, the output will be the number of values in the CSV string
'Delimiter symbol is default to ","
'20091215, Changing the parameter to be able to nesting the UDF
'Public Function CSV(ByRef rRange As Range, Optional ByVal n As Variant, Optional ByVal strDelimiter As Variant) As Variant
Public Function DSV(ByVal rRange As Variant, Optional ByVal N As Variant, Optional ByVal strDelimiter As Variant) As Variant
'Using "," as default de-limitator
If IsMissing(strDelimiter) Then strDelimiter = ","
Dim x As Variant
Dim vResult As Variant
'Cast the input to string type before proceeding
x = Split(rRange, strDelimiter)
On Error Resume Next
If IsMissing(N) Then
vResult = UBound(x) + 1
Else
vResult = x(N - 1) 'Because split() returns an array whose index staring from 0
If Err <> 0 Then vResult = "Error"
'If Err <> 0 Then vResult = rRange.Cells(1, 1)
On Error GoTo 0
End If
DSV = vResult
End Function 作者: 小文和小武 时间: 2011-11-8 14:35