Option Explicit
Function str3(irng As Range, ii As Integer)
Dim i As Long
Dim j As Long
Dim data
Dim str2(), str1, str4
'Debug.Print irng.Address
data = irng.Value
ReDim str2(1 To UBound(data, 1))
For i = 1 To UBound(data, 1)
str1 = 1: str4 = 1
For j = 2 To UBound(data, 2)
'Debug.Print data(i, j)
If data(i, j) <> "" Then
If data(i, j) = data(i, j - 1) Then
str4 = str4 & "_" & str1
Else
str1 = str1 + 1
str4 = str4 & "_" & str1
End If
End If
Next
'Debug.Print str2(i)
str2(i) = str4
Next
'Debug.Print str2(ii)
'str3 = str2(ii)
ReDim ds(0 To UBound(data, 2))
Dim jj As Integer, r()
For i = 1 To UBound(str2)
r = Split(str2(i), "_")
For j = 1 To r(UBound(r))
jj = WorksheetFunction.CountIf(WorksheetFunction.Transpose
(r), j)
ds(jj) = ds(jj) + 1
Next
Next
str3 = ds(ii)
End Function
' this UDF has also #VALUE! error.