userform搜索查找和返回数据

时间:2017-03-22 11:38:46

标签: vba excel-vba excel

我在尝试搜索并返回电子表格中的所有数据时收到错误(无效的过程调用或参数)。谁能帮忙。在此先感谢!!!

代码如下:

Private Sub PlaceValues(Index As Long)
With Me
    .txtLoggedBy.Value = CallDetails(Index).Value
    .txtCallNumber.Value = CallDetails(Index).CallNumber
    .txtDateField.Value = CallDetails(Index).DateField
    .txtTitle.Value = CallDetails(Index).Title
    .cmbOwnerField.Value = CallDetails(Index).OwnerField
    .txtDescription.Value = CallDetails(Index).Description
    .txtSolution.Value = CallDetails(Index).Solution
End With
End Sub

亲切的问候。

CallDetails代码是:

Public Function Find_CallNumbers(NumberToFind As String) As Collection

Dim rng_to_search As Range
Dim rFound As Range
Dim FirstAddress As String
Dim FoundItem As clsCallDetails

Set CallDetails = New Collection

With ThisWorkbook.Worksheets("Database")
    Set rng_to_search = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With

With rng_to_search
    'Look for the first instance.
    Set rFound = .Find(what:=NumberToFind, _
                       after:=.Cells(1, 1), _
                       LookIn:=xlValues, _
                       LookAt:=xlWhole, _
                       SearchDirection:=xlNext)
    If Not rFound Is Nothing Then
        FirstAddress = rFound.Address
        Do
            Set FoundItem = New clsCallDetails 'Create a new instance of the class to hold the details.
            With FoundItem
                .Title = rFound.Offset(, 1)
                .LoggedBy = rFound.Offset(, 2) 'Offset from column A by 1 column, so column B.
                .CallNumber = rFound.Offset(, 3)
                .DateField = rFound.Offset(, 4)
                .OwnerField = rFound.Offset(, 6)
                .Description = rFound.Offset(, 7)
                .Solution = rFound.Offset(, 8)

            End With
            CallDetails.Add FoundItem 'Add the class instance to our collection.
            Set rFound = .FindNext(rFound) 'Look for the next value.

        'Continue searching until we reach the top again.
        Loop While Not rFound Is Nothing And rFound.Address <> FirstAddress
    End If
End With

End Function

1 个答案:

答案 0 :(得分:0)

您正在将Long类型的变量传递给期望类型为String的函数。变化

Public Function Find_CallNumbers(NumberToFind As String) As Collection

Public Function Find_CallNumbers(NumberToFind As Long) As Collection