|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
请测试
Sub bcf()
Start = Timer
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rst As New ADODB.Recordset
Dim SQL$, SQL1$, f&, i&, arr()
On Error Resume Next
Set cnn = CreateObject("adodb.connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & "\atm.mdb"
SQL1 = "select distinct 材料名称,型号规格,材料名称&型号规格 as 两列 from [Excel 8.0;Database=" & ThisWorkbook.FullName & "].[入库单$n8:p" & Sheets("入库单").[o65536].End(xlUp).Row & "]"
SQL = "select a.材料名称,a.型号规格 from (" & SQL1 & ") a left join (select 材料名称&型号规格 as 两列 from 材料编码表) b on a.两列=b.两列 where b.两列 is null"
rs.Open SQL, cnn, 1, 3
If rs.RecordCount Then
Range("N8:P8").Copy [z1]
[aa2].CopyFromRecordset rs
SQL = "select val(right(材料编码,5)) as zd from 材料编码表 where 材料编码 is not null"
rst.Open SQL, cnn, 1, 3
If rst.RecordCount Then
arr = rst.GetRows
f = WorksheetFunction.Max(arr)
End If
ReDim arr(1 To rs.RecordCount, 0)
For i = 1 To rs.RecordCount
arr(i, 0) = "GA" & Format(f + i, "00000")
Next
[z2].Resize(i - 1) = arr
SQL = "insert into 材料编码表 select * from [Excel 8.0;Database=" & ThisWorkbook.FullName & "].[入库单$z1:ab" & Sheets("入库单").[z65536].End(xlUp).Row & "]"
cnn.Execute SQL
[z1].CurrentRegion.Clear
End If
rs.Close
rst.Close
cnn.Close
Set rs = Nothing
Set rst = Nothing
Set cnn = Nothing
MsgBox "更新完毕。用时 " & Timer - Start & " 秒"
End Sub |
评分
-
1
查看全部评分
-
|