|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
原帖由 lisan 于 2011-1-9 15:59 发表
若该序列号存在,则在库存.xls的G列自动填入当前日期,且在销售表.xls的C列填入已登记。
若该序列号存在,能否在销售表.xls的C列 再填入 已登记 ?
Sub Macro1()
Dim cnn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim SQL$, arr, i&
arr = Range("b3:b" & [b65536].End(xlUp).Row)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.Path & "\库存.xls"
[b2].CurrentRegion.Offset(1, 1).ClearContents
For i = 1 To UBound(arr)
SQL = "select * from [库存表$] where 序列号='" & arr(i, 1) & " '"
Set rs = New ADODB.Recordset
rs.Open SQL, cnn, 1, 3
If rs.RecordCount Then
SQL = "update [库存表$] set 销售日期 =#" & Date & "# where 序列号='" & arr(i, 1) & " '"
Set rs = cnn.Execute(SQL)
Cells(i + 2, 3) = "已登记" '新加
Else
Cells(i + 2, 3) = "库存不存在"
End If
Next
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub |
|