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
调试#值!关于VBA_Vba - Fatal编程技术网

调试#值!关于VBA

调试#值!关于VBA,vba,Vba,当我在下面的VBA代码中运行TEST()时,结果如下所示 但如果我在Excel工作表中运行LASTEST_DATE(..),它会显示#VALUE!错误 你知道为什么吗? Public Function LASTEST_DATE(arg1作为字符串,arg2作为字符串)作为日期 设置aSheet=工作表(“L4 CSU计划Excel转储”) Dim lastestDate As Date 带自动范围(“A2:AA5000”) 设置系统=.Find(What:=arg1,LookIn:=xlVa

当我在下面的VBA代码中运行TEST()时,结果如下所示

但如果我在Excel工作表中运行LASTEST_DATE(..),它会显示#VALUE!错误

你知道为什么吗?

Public Function LASTEST_DATE(arg1作为字符串,arg2作为字符串)作为日期
设置aSheet=工作表(“L4 CSU计划Excel转储”)
Dim lastestDate As Date
带自动范围(“A2:AA5000”)
设置系统=.Find(What:=arg1,LookIn:=xlValues)
若不是,那个么系统什么都不是
firstAddress=系统地址
做
如果(aSheet.Range(“AA”和System.Row)>lastestDate),则
lastestDate=aSheet.Range(“AA”和System.Row).Value
如果结束
设置系统=.FindNext(系统)
非系统时循环为Nothing和System.Address firstAddress
如果结束
以
LASTEST_DATE=lastestDate
端函数
公共子测试()
调试打印(最新日期(3100100,“系统调试”))
端接头

由于VBA没有短路评估,因此正确的表达式

Public Function LASTEST_DATE(arg1 As String, arg2 As String) As Date
    Set aSheet = Worksheets("L4 CSU Schedule Excel Dump")
    Dim lastestDate As Date

    With aSheet.Range("A2:AA5000")
        Set System = .Find(What:=arg1, LookIn:=xlValues)

        If Not System Is Nothing Then
            firstAddress = System.Address

            Do
                If (aSheet.Range("AA" & System.Row) > lastestDate) Then
                    lastestDate = aSheet.Range("AA" & System.Row).Value
                End If

                Set System = .FindNext(System)
            Loop While Not System Is Nothing And System.Address <> firstAddress
        End If

    End With

    LASTEST_DATE = lastestDate
End Function

Public Sub TEST()
    Debug.Print (LASTEST_DATE(3100100, "System Commissioned"))
End Sub
Loop While Not System Is Nothing And System.Address <> firstAddress