VBA 查找值所在的行号

目录
Function FindRowOfValue(ws As Worksheet, val As Variant, colNum As Long, startRow As Long)
    Dim r As Long
    With ws
    For r = startRow To .Range(.Cells(startRow, colNum), .Cells(startRow, colNum)).CurrentRegion.Rows.Count()
        If .Cells(r, colNum).Value = val Then
            FindRowOfValue = r
            Exit Function
        End If
    Next
    End With
End Function

推广:阿里云百炼大模型 9折优惠 + 所有模型各百万免费Token →