|
楼主 |
发表于 2017-7-17 15:37
|
显示全部楼层
本帖最后由 一指禅62 于 2017-7-17 15:43 编辑
- Private Sub Worksheet_Change(ByVal Target As Range)
- Rem 明细表代码。第8行为上期结存,在A9单元格粘贴,并做相应计算
- If Target.Address = "$G$4" Then
- Sheet5.Protect UserInterfaceOnly:=True
- If Trim(Target.Value) <> "" Then
- Dim rs As New ADODB.Recordset, SQL$, R%, key$
- Range("A9:G65536").ClearContents
- Range("A9:G65536").Borders.LineStyle = xlNone
- SQL = "Select 月,日,凭证类,摘要,入库数量,出库数量 from [DataBase$] " & _
- "where 物料编码='" & Trim(Target.Value) & "' order by 月,日,凭证类 asc"
- rs.Open SQL, cnn, 1, 3
- If rs.RecordCount > 0 Then
- Range("A9").CopyFromRecordset rs
- R = rs.RecordCount + 8
- Range("G9:G" & R).FormulaR1C1 = "=R[-1]C7+RC5-RC6"
- Range("D" & R + 1) = "合计"
- Range("E" & R + 1 & ":F" & R + 1).FormulaR1C1 = "=SUM(R8C:R" & R & "C)"
- Range("A8:G" & R + 1).Borders.LineStyle = xlContinuous
- End If
- rs.Close
- Set rs = Nothing
- End If
- End If
- End Sub
复制代码
因没有时间,其他表未做修改。
|
|