|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
<P>
6D3qZKhc.zip
(101.79 KB, 下载次数: 62)
Sub total()
For i = 2 To Sheets("分录表").UsedRange.Rows.Count
If Sheets("分录表").Range("H" & i) = "" Then Sheets("分录表").Range("H" & i) = " " '填写空格即可
Next i
m = Sheets("汇总表").Range("e2")
Set x = CreateObject("ADODB.connection")
Set yy = CreateObject("adodb.recordset")
x.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;';Data Source=" & ThisWorkbook.FullName
Sql = "select 总账科目,明细科目," & _
"dsum('借方金额','[分录表$]','总账科目=' & '''' & 总账科目 & '''' & ' and 明细科目=' & '''' & 明细科目 & '''' & ' and 月=" & m & "') as 月汇总1," & _
"dsum('贷方金额','[分录表$]','总账科目=' & '''' & 总账科目 & '''' & ' and 明细科目=' & '''' & 明细科目 & '''' & ' and 月=" & m & "') as 月汇总2," & _
"dsum('借方金额','[分录表$]','总账科目=' & '''' & 总账科目 & '''' & ' and 明细科目=' & '''' & 明细科目 & '''' & ' and 月<=" & m & "') as 总1," & _
"dsum('贷方金额','[分录表$]','总账科目=' & '''' & 总账科目 & '''' & ' and 明细科目=' & '''' & 明细科目 & '''' & ' and 月<=" & m & "') as 总2" & _
" from [分录表$] group by 总账科目,明细科目"
'MsgBox Sql
yy.Open Sql, x, 1, 1
'Sheet1.Range("A1").CopyFromRecordset yy
'MsgBox yy.RecordCount
For i = 7 To 94
yy.movefirst
Do While Not yy.EOF
If Sheets("汇总表").Range("A" & i) = Trim(yy(0)) And Sheets("汇总表").Range("B" & i) = Trim(yy(1)) Then
Sheets("汇总表").Range("e" & i) = yy(2)
Sheets("汇总表").Range("f" & i) = yy(3)
Sheets("汇总表").Range("g" & i) = yy(4)
Sheets("汇总表").Range("h" & i) = yy(5)
Exit Do
End If
yy.movenext
Loop
Next i
yy.Close
Set yy = Nothing: Set x = Nothing
MsgBox "汇总完毕"
End Sub</P>
<P>这段代码什么意思?"汇总表"是如何产生的?</P>
<P>顺便上传个VBA解码器,方便大家学习.</P> |
|