1

そこで、テキスト ボックスの入力を使用して別のシートで対応する値を検索する関数を作成しました。問題は、一致が見つからない場合、無限ループに陥ることです。クラッシュしないようにループを制限できますか? ループを制限するのではなく、別の解決策があれば、私はすべて耳にします。これが私が取り組んでいるものです:

Function Most_Recent_Deployment(Label1 As String, Label2 As String, Label3 As String) As Long
    Dim all_rows As Range
    Dim row As Range
    Dim LastCell As Range
    Dim LastCellRowNumber As Long
    Set LastCell = Sheet7.Cells(Sheet7.Rows.Count, "A").End(xlDown).End(xlUp)
    LastCellRowNumber = LastCell.row + 1
    Set row = Sheet7.Range("A:A").Find(Label1, LookIn:=xlValues, After:=Cells(LastCellRowNumber, "A"), SearchDirection:=xlPrevious)
    Do While row.row > 1

        If (Sheet7.Cells(row.row, 2).Text = Label2) And (Sheet7.Cells(row.row, 3).Text = Label3) Then
            Most_Recent_Deployment = row.row
            Exit Function
        End If
        LastCellRowNumber = row.row
        Set row = Sheet7.Range("A:A").Find(Label1, LookIn:=xlValues, After:=Cells(LastCellRowNumber, "A"), SearchDirection:=xlPrevious)

    Loop
    Most_Recent_Deployment = 0
End Function
4

2 に答える 2

0

Do Until を試してみてください。例えば:

Do Until IsEmpty(Cells(iRow, 1)) 
    ' Store the current cell value in the dCellValues array
    dCellValues(iRow) = Cells(iRow, 1).Value
    iRow = iRow + 1 
Loop  

ExcelFunctions.netからのコード。

于 2015-04-01T16:14:45.520 に答える