-1

我正在尝试.Find在 VB 2010 中使用以查找函数的结果。

这是我的代码:

firstFind = xlWorkSheet.Range("E10", "CM10").Find(searchDate, ,     Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False)

我都试过了xlValuesxlFormulas

excel函数非常简单,如下所示:

=G9+7

结果是一个日期,7 月 19 日,这就是我想要搜索的内容。

BR塞巴斯蒂安

4

3 回答 3

0

先说第一件事。Excel 将日期视为整数,因此 19-Jul 实际上是一个数字(将 =G9+7 的单元格设置为通用)例如日期 2012 年 7 月 19 日 = 41109。希望这会有所帮助。

于 2012-07-09T13:16:33.113 回答
0

你不能循环遍历列而不是使用 find 函数吗?像这样的东西可能会更有效或更容易定制:

Sub Test()

    Dim iColumnSearch As Long
    Dim dtSearchDate As Date
    Dim rngFoundInCell As Range

    dtSearchDate = "7/16/2012"

    '- loop through columns E to CM (Column #'s 5 to 91)
    For iColumnSearch = 5 To 91
        If Cells(10, iColumnSearch).Value = dtSearchDate Then

            Set rngFoundInCell = Cells(10, iColumnSearch)
            Exit For
        End If
    Next iColumnSearch

    If Not rngFoundInCell Is Nothing Then '-if was found
        MsgBox "Found in cell: " & rngFoundInCell.Parent.Name & "!" & rngFoundInCell.Address(External:=False)
    End If


    Set rngFoundInCell = Nothing

End Sub

更新:

请注意,上面的代码正在搜索日期“2012 年 7 月 16 日”,因为我没有看到您的搜索字符串所在的位置。您可以将该行替换为:

dtSearchDate = Range("G9").value + 7
于 2012-07-09T21:34:58.850 回答
0

这是我在不使用的情况下解决问题的方法.find

Const FOUND As Integer = 1, NOT_FOUND = 0
Dim worksheetNr As Integer = 0, columnNr As Integer, dateFound As Integer = NOT_FOUND

While worksheetNr < xlWorkBook.Worksheets.Count And dateFound = NOT_FOUND

    Try
        xlWorkSheet = xlWorkBook.Worksheets(worksheetNr)
        xlWorkSheet.Activate()
        columnNr = 7
        While dateFound = NOT_FOUND And (columnNr < 100)
            If (xlWorkSheet.Cells(10, columnNr).Value.Equals(searchDate)) Then
                dateFound = FOUND
            Else
                columnNr += 1
            End If

        End While

    Catch ex As Exception
        Console.Write("")
    End Try

End While
于 2012-07-10T11:04:31.667 回答