包材.rar
(15.58 KB, 下载次数: 5)
附件中成品料号后面单元格更改,下面的料号等跟随更改。
但是文件保存重新打开后下面的料号信息不能自动更改是怎么回事?
代码:
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 2 And Target.Row = 3 Then Rows("7:300").ClearContents Set cnn = CreateObject("adodb.connection") cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName Sql = "select * from [基础数据$] where 成品料号='" & Cells(3, 2).Value & "'" Set rst = CreateObject("adodb.Recordset") rst.Open Sql, cnn, 1, 1 k = 5 Do While Not rst.EOF Cells(k, 1).Value = k - 4 Cells(k, 2).Value = rst("包材料号") Cells(k, 3).Value = rst("包材品名") Cells(k, 4).Value = rst("规格") Cells(k, 5).Value = rst("单耗") k = k + 1 rst.movenext Loop cnn.Close Set cnn = Nothing End If End Sub
|