Функция VBA, возвращающая '#VALUE!' - PullRequest
0 голосов
/ 27 апреля 2018
Public Function MostOccuring(items() As Variant) As String
    Dim count() As Integer
    Dim strings() As Object
    Dim Index As Integer
    For Index = 0 To items.Length - 1
        If srings.Exists(items(Index)) Then
            count(strings.IndexOf(items(Index))) = 1 + count(strings.IndexOf(items(Index)))
        Else
            count(Index) = 1
            strings(Index) = items(Index)
        End If
    Next
    End
    MostOccuring = strings(count.IndexOf(count.Max()))

End Function

Это моя функция mostocurring
This is how I call it

Вот как я это называю

И он возвращает «# ЗНАЧЕНИЕ!». Зачем? Он должен вернуть наиболее встречающуюся строку клеток. Благодаря.

1 Ответ

0 голосов
/ 27 апреля 2018

Вы также можете попробовать что-то вроде этого ...

Public Function MostOccuring(items As Range) As String
Dim cell As Range
Dim dict, it
Dim maxCnt As Long

Set dict = CreateObject("Scripting.Dictionary")
For Each cell In items
    If Not dict.exists(cell.Value) Then
        dict.Item(cell.Value) = 1
    Else
        dict.Item(cell.Value) = dict.Item(cell.Value) + 1
    End If
Next cell

For Each it In dict.keys
    If dict.Item(it) > maxCnt Then
        maxCnt = dict.Item(it)
        MostOccuring = it
    End If
Next it
End Function
...