Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Excel.Find,函数vb2010的结果_Vb.net_Excel - Fatal编程技术网

Vb.net Excel.Find,函数vb2010的结果

Vb.net Excel.Find,函数vb2010的结果,vb.net,excel,Vb.net,Excel,我试图在VB2010中使用.Find,以查找函数的结果 这是我的代码: firstFind = xlWorkSheet.Range("E10", "CM10").Find(searchDate, , Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False) 我尝试了xlValues和xlFormulas

我试图在VB2010中使用
.Find
,以查找函数的结果

这是我的代码:

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

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

=G9+7
结果是一个日期,7月19日,这就是我想要搜索的


塞巴斯蒂安

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

您不能在列中循环,而不是使用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
更新:

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

dtSearchDate = Range("G9").value + 7

以下是我在不使用
的情况下解决问题的方法。查找

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
常量为整数=1,未找到=0
Dim worksheetNr为整数=0,ColumnR为整数,dateFound为整数=未找到
而工作表nr