|
本帖最后由 jokerzhh 于 2018-6-27 15:45 编辑
- Dim Rng As Range
- Set Rng = Worksheets("Demand").Range(Worksheets("Demand").Cells(1, 3), Worksheets("Demand").Cells(demandLastRow, 5))
复制代码 更新: 上传原文件, 代码在module2, check_demand()这个function, 在main里面点击scoring运行, 我想做的是查找传入的product在demand表里最后计划的日期, 然后和当前日期对比. 用for循环实现是不是会很慢的? 谢谢
更新6/27:谢谢各位的帮忙, 结合@魂断蓝桥 @zopey @lsdongjh 3位的代码实现了, 代码如下:
- Public Function check_demand(product As String, workingDate As Date) As Boolean
- Dim cnn As Object
- Dim Sql As String
- check_demand = False
- Set cnn = CreateObject("ADODB.CONNECTION")
- cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
- Sql = "select max([Delivery Date]) as lastdate from [Demand$a1:e] where module_type='" & product & "' group by [module_type] "
- cnn.Execute(Sql)
-
- Set Rst2 = CreateObject("adodb.Recordset")
- Rst2.Open Sql, cnn, 3, 1
- If Rst2("lastdate") >= workingDate Then
- check_demand = True
- End If
- cnn.Close: Set cnn = Nothing
- End Function
复制代码 最后, 再次谢谢各位的帮助 :)
|
|