按值Excel-VBA查找范围

时间:2016-04-04 11:58:02

标签: excel vba excel-vba

我需要一个函数或其他东西来返回一个找到指定值的范围。

我正在考虑循环遍历指定的范围检查,如果每个单元格中的值等于我指定的值并构建范围。有更优雅的方法吗?

2 个答案:

答案 0 :(得分:0)

这是我建立的一个功能。它返回一个联合范围,其中找到了所需的值:

Private Function FindRange(what As String, lookin As Range) As Range

    Dim cell As Range

    On Error GoTo errhandler

    For Each cell In lookin.Cells
        If UCase(cell.Value) = UCase(what) Then

            If findrange Is Nothing Then
                Set findrange = cell
            Else
                Set findrange = Application.Union(findrange, cell)
            End If

        End If
    Next cell

    Exit Function

errhandler:
    findrange = CVErr(xlErrNA)

End Function

答案 1 :(得分:0)

尝试以下代码。您可以使用公式在单元格中获得结果。

 IntPtr pDll = NativeMethods.LoadLibrary(System.Configuration.ConfigurationManager.AppSettings["MyDll"]);
希望你满意吗?