|
楼主 |
发表于 2007-9-26 16:07
|
显示全部楼层
<p><br/>Private Sub CommandButton1_Click()<br/> On Error Resume Next<br/> Application.ScreenUpdating = False<br/> With Sheets("财务分析表")<br/> Call 清空表格数据<br/> If ComboBox1 = "" Then<br/> MsgBox "点击借方(贷方)汇总、年度", vbInformation, "凭证处理系统"<br/> Call 清空表格数据: Exit Sub<br/> End If<br/> SQL = "Select * From 科目表"<br/> If ComboBox3 = "" Then<br/> SQL = SQL & " Order by 科目编码"<br/> Else<br/> SQL = SQL & " Where 类型='" & ComboBox3.Text & "' Order by 科目编码"<br/> End If<br/> RST1.Open SQL, CNN, adOpenKeyset, adLockOptimistic<br/> If RST1.EOF Or RST1.BOF Then<br/> MsgBox "没有发现" & ComboBox3.Text & "类的会计科目!", vbInformation, "凭证处理系统"<br/> Call 清空表格数据: RST1.Close: Set RST1 = Nothing: Exit Sub<br/> End If<br/> Cells(2, "B") = ComboBox1.Text & "年度" & ComboBox3.Text & "科目分月汇总表"<br/> ProgressBar1.Max = RST1.RecordCount '进度条的最大值<br/> For I = 1 To RST1.RecordCount<br/> MaxRow = Range("B65536").End(xlUp).Row + 1<br/> ProgressBar1.Value = I '进度条的动态值<br/> Cells(MaxRow, "B") = RST1.Fields("科目编码")<br/> Cells(MaxRow, "C") = RST1.Fields("总账科目")<br/> Cells(MaxRow, "D") = RST1.Fields("明细科目")<br/> Cells(MaxRow, "S") = RST1.Fields("现金编码")<br/> If OptionButton1.Value = True Then Cells(MaxRow, "E") = "借"<br/> If OptionButton2.Value = True Then Cells(MaxRow, "E") = "贷"<br/> If OptionButton3.Value = True Then Cells(MaxRow, "E") = "※"<br/> If OptionButton4.Value = True Then<br/> Cells(MaxRow, "E") = "借" '科目方向填充<br/> Cells(MaxRow + 1, "B") = RST1.Fields("科目编码")<br/> Cells(MaxRow + 1, "C") = RST1.Fields("总账科目")<br/> Cells(MaxRow + 1, "D") = RST1.Fields("明细科目")<br/> Cells(MaxRow + 1, "E") = "贷" '科目方向填充<br/> Cells(MaxRow + 1, "S") = RST1.Fields("现金编码")<br/> End If<br/> For Months = 1 To CInt(ComboBox2.Text) '科目逐月汇总<br/> Call MonthCount '逐月汇总模块<br/> Next Months<br/> RST1.MoveNext<br/> Next I<br/> RST1.Close: Set RST1 = Nothing<br/> Range("R4:R" & MaxRow + 1).Formula = "=SUM(F4:Q4)"<br/> Range("F4:R" & MaxRow + 1).NumberFormatLocal = "#,##0.00"<br/> Call 字体线框4<br/> If OptionButton4.Value = True Then Call 月份汇总数据<br/> End With<br/> Unload Me<br/> Application.ScreenUpdating = True<br/>End Sub</p><p></p><p>Sub MonthCount()<br/> On Error Resume Next<br/> Dim JFHJ As Double, DFHJ As Double, JDCY As Double<br/> SQL = "Select sum(借方金额) as 借方合计,sum(贷方金额) as 贷方合计 From 分录表 "<br/> SQL = SQL & " Where 年=" & CInt(ComboBox1.Text) & ""<br/> SQL = SQL & " And 月=" & Months & ""<br/> SQL = SQL & " And 科目编码='" & Trim(Cells(MaxRow, "B")) & "'"<br/> RST2.Open SQL, CNN, adOpenKeyset, adLockOptimistic<br/> JFHJ = RST2.Fields("借方合计")<br/> DFHJ = RST2.Fields("贷方合计")<br/> If OptionButton1.Value = True Then<br/> Cells(MaxRow, Months + 5) = JFHJ '借方<br/> End If<br/> If OptionButton2.Value = True Then<br/> Cells(MaxRow, Months + 5) = DFHJ '贷方<br/> End If<br/> If OptionButton3.Value = True Then<br/> Select Case RST1.Fields("方向")<br/> Case "借"<br/> JDCY = JFHJ - DFHJ<br/> Case "贷"<br/> JDCY = DFHJ - JFHJ<br/> End Select<br/> Cells(MaxRow, Months + 5) = JDCY '借贷差额<br/> End If<br/> If OptionButton4.Value = True Then<br/> Cells(MaxRow, Months + 5) = JFHJ '借方<br/> Cells(MaxRow + 1, Months + 5) = DFHJ '贷方<br/> End If<br/> JFHJ = 0: DFHJ = 0: JDCY = 0<br/> RST2.Close: Set RST2 = Nothing<br/>End Sub</p>
[此贴子已经被作者于2007-9-26 16:08:26编辑过] |
|