【问题标题】:UDF inside UDF doesn't work (ByRef argument type missmatch)UDF 中的 UDF 不起作用(ByRef 参数类型不匹配)
【发布时间】:2016-08-07 14:36:16
【问题描述】:

我正在构建一个使用另一个内部的 udf,但我在迭代变量中收到错误“ByRef argument missing”,我有这个字符串“-60981--:54044,-60981--:54044,-60981 --:53835,-60981--:53835," 我想删除重复项,所以我想取回这个字符串 "-60981--:54044,60981--:53835," 这是第一个 UDF,这是我想在第二个中使用的: 第一个 UDF:GetJSON

Public Function getJSON(JSONObject As String, ObjectNumber As Integer, GetBack As Integer) As Variant
' 0 = object and property
' 1 = object
' 2 = property of object
Dim CompleteObject As String
Dim ObjectsInJSON As Integer
ObjectsInJSON = Len(JSONObject) - Len(Application.Substitute(JSONObject, ",", ""))

If ObjectNumber <= ObjectsInJSON Then
If ObjectNumber = 1 Then
CompleteObject = Left(JSONObject, Application.Find(",", JSONObject, 1) - 1)
Else
CompleteObject = Application.Substitute(Mid(JSONObject, FindN(",",JSONObject, 1, ObjectNumber - 1) + 1, FindN(",", JSONObject, 1, ObjectNumber) - FindN(",", JSONObject, 1, ObjectNumber - 1)), ",", "")
End If
Select Case GetBack
Case Is = 0
getJSON = CompleteObject
Case Is = 1
getJSON = Left(CompleteObject, Application.Find(":", CompleteObject, 1) - 1)
Case Is = 2
getJSON = Right(CompleteObject, Len(CompleteObject) - Application.Find(":", CompleteObject, 1))
End Select
Else
getJSON = CVErr(xlErrNA)
End If
End Function

第二个 UDF GetUniqueTrailers

Public Function GetUniqueTrailers(JSON As String) As String
Dim i, TrailersCounter As Integer
TrailersCounter = Len(JSON) - Len(Application.Substitute(JSON, ",", ""))
Dim ArrayOfTrailers() As String
For i = 1 To TrailersCounter
'here below occurs this error, in the i variable
If IsError(Application.VLookup(getJSON(JSON, i, 0), ArrayOfTrailers, 1, False)) Then
ReDim Preserve ArrayOfTrailers(i)
ArrayOfTrailers(i) = getJSON(JSONstring, i, 0)
Next i
'convert array to text
For i = 1 To UBound(ArrayOfTrailers)
GetUniqueTrailers = getuniquetraileres & ArrayOfTrailers(i) & ","
Next i

End Function

【问题讨论】:

    标签: vba pass-by-reference udf


    【解决方案1】:

    完成了,我必须再做一个“concatenateRange”UDF,它只是加入每个单元格值 =concatenateRange("a1:a100") 例如,我确实修改了这个 UDF:

    Public Function GetUniqueTrailers(TheRange As Range) As String
    Dim i As Integer
    Dim tempRange As Range
    Dim tempText As String
    
    For i = 1 To TheRange.Cells.Count
    Set tempRange = Range(TheRange.Item(1).Address, TheRange.Item(i).Address)
    tempText = ConcatenateRange(tempRange)
    If i = 1 Then
    GetUniqueTrailers = TheRange.Item(1).Value & ","
    Else
    If InStr(1, GetUniqueTrailers, TheRange.Item(i).Value, vbTextCompare) <= 0 Then
    GetUniqueTrailers = GetUniqueTrailers & TheRange.Item(i).Value & ","
    End If
    End If
    Next i
    End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      • 2017-06-08
      相关资源
      最近更新 更多