|
本帖最后由 alimjan15 于 2024-2-13 16:02 编辑
大神们请查看 一下函数看看。 我要做这个函数 target必要参数,target2和str 要 选用参数。 但实际运行中excel 但愿输入该函数时 3个参数都选中才有正确结果, 第二和第三参数任意一个没有指定就显示#value 。 帮我怎么改 才能达到 第二和第三参数没有的情况下 正常运算出来。
- Public Function test11(target As Range, target2 As Range, str As String) As Long
- Application.Volatile
- Dim colDistinct As New Collection, rng As Range, rng1 As Range
- On Error Resume Next
- If target2.Count = 0 Or Len(str) = 0 Then
- For Each rng In target
- If Not IsEmpty(rng.Value) Then
- colDistinct.Add rng.Value
- End If
- Next
- Else
- For Each rng In target
- If Not IsEmpty(rng.Value) And target2.Cells(rng.Row - 1, 1).Value = str Then
- colDistinct.Add rng.Value
- End If
- Next
- End If
- test11 = colDistinct.Count
- End Function
复制代码
|
|