|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub t()
- Dim cnn As New Connection, SQL$, rs As New ADODB.Recordset, arr
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
- If cnn.State <> 1 Then
- MsgBox "未能成功连接数据库!", vbCritical + vbOKOnly, "警告"
- Exit Sub
-
- End If
- SQL = "select 订单号,规格,轮型,计划长度 from [录入数据$] where 订单号<>'' or 订单号 is not null"
- arr = cnn.Execute(SQL).GetRows
-
- For i = 0 To UBound(arr, 2)
- SQL = "select * from [订单录入$] where 订单号='" & arr(0, i) & "' and 规格='" & arr(1, i) & _
- "' and 轮型='" & arr(2, i) & "' and 计划长度='" & arr(3, i) & "'"
- rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
- If rs.RecordCount = 0 Then
- Sheets("录入数据").Range(Cells(i + 2, 1), Cells(i + 2, 15)).Interior.Color = 255
- End If
- rs.Close
- Next
-
- SQL = "update [录入数据$] a,[订单录入$] b set a.计划件数=b.计划件数 where (a.订单号<>'' or a.订单号 is not null)" & _
- " and a.订单号=b.订单号 and a.规格=b.规格 and a.轮型=b.轮型 and a.计划长度=b.计划长度"
- cnn.Execute SQL
-
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|