ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: zbs112

[求助]分季度汇总各明细科目的数据到LISTVIEW

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-7-6 09:05 | 显示全部楼层

窗体选定项目加载代码如下

Private Sub CheckBox1_Change()
  On Error Resume Next
  With ListView1
    .ColumnHeaders.Add , , "1月", 60
    .ColumnHeaders.Add , , "2月", 60
    .ColumnHeaders.Add , , "3月", 60
    .ColumnHeaders.Add , , "合计", 65
  End With
  CheckBox1.Enabled = False
End Sub
Private Sub CheckBox2_Change()
  On Error Resume Next
  With ListView1
    .ColumnHeaders.Add , , "4月", 60
    .ColumnHeaders.Add , , "5月", 60
    .ColumnHeaders.Add , , "6月", 60
    .ColumnHeaders.Add , , "合计", 65
  End With
  CheckBox2.Enabled = False
End Sub
Private Sub CheckBox3_Change()
  On Error Resume Next
  With ListView1
    .ColumnHeaders.Add , , "7月", 60
    .ColumnHeaders.Add , , "8月", 60
    .ColumnHeaders.Add , , "9月", 60
    .ColumnHeaders.Add , , "合计", 65
  End With
  CheckBox3.Enabled = False
End Sub
Private Sub CheckBox4_Change()
  On Error Resume Next
  With ListView1
    .ColumnHeaders.Add , , "10月", 60
    .ColumnHeaders.Add , , "11月", 60
    .ColumnHeaders.Add , , "12月", 60
    .ColumnHeaders.Add , , "合计", 65
  End With
  CheckBox4.Enabled = False
End Sub

[此贴子已经被作者于2006-7-6 9:34:36编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-7-6 09:35 | 显示全部楼层

[求助]请帮忙修改和续写代码(本楼附件)

当选定汇总科目的类别时,LISTVIEW同步刷新的代码如下:

Private Sub ComboBox2_Change()
  On Error Resume Next
  Stpath = ThisWorkbook.Path & Application.PathSeparator & "分录表.mdb"
  CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath
  SQL = "select 科目编码,总账科目,明细科目,方向 from kmb where 类型='" & ComboBox2.Text & "' order by 科目编码"
  RST.Open SQL, CNN, adOpenKeyset, adLockOptimistic
  ListView1.ListItems.Clear
  M = RST.RecordCount
  PBar1.Max = M  '进度条的最大值
  For I = 1 To M
    PBar1.Value = I '进度条的动态值
    With ListView1.ListItems.Add(, , RST.Fields("科目编码"))
      .SubItems(1) = IIf(IsNull(RST.Fields("总账科目")), "", RST.Fields("总账科目"))
      .SubItems(2) = IIf(IsNull(RST.Fields("明细科目")), "", RST.Fields("明细科目"))
      .SubItems(3) = IIf(IsNull(RST.Fields("方向")), "", RST.Fields("方向"))
    End With
    RST.MoveNext
  Next I
  RST.Close
  CNN.Close
  Set RST = Nothing
  Set CNN = Nothing
  PBar1.Value = False
End Sub


JJ29IjDO.rar (34.87 KB, 下载次数: 28)
[此贴子已经被作者于2006-7-6 12:06:42编辑过]

sTXjn6p8.rar

31.87 KB, 下载次数: 12

[求助]请帮忙修改和续写代码(本楼附件)

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-7-6 12:08 | 显示全部楼层

[求助]要求的结果如图所示

盼高手修改或续写代码


[求助]指定季度汇总各月各科目的数据到LISTVIEW

[求助]指定季度汇总各月各科目的数据到LISTVIEW

TA的精华主题

TA的得分主题

发表于 2006-7-6 15:10 | 显示全部楼层
TO:zbs112兄
权做帮你顶一次.
从设计的界面,兄极具灵气的.
而且,依我对您的了解,你是有能力独立完成的,基本的技术元素你都已经掌握了.
象这种专业性很强的东西,我看着就眼晕,写起来实在是繁琐.我很懒,所以....

TA的精华主题

TA的得分主题

发表于 2006-7-6 18:16 | 显示全部楼层

CvCG5K1k.rar (31.52 KB, 下载次数: 48)

 

Private Sub CommandButton1_Click()
    Dim summ As Double
    On Error Resume Next
    If ComboBox1.Text = "" Or ComboBox2.Text = "" Or (OptionButton1.Value = False And OptionButton2.Value = False) Then
        ListView1.ListItems.Clear
        MsgBox "请点选科目的类别、年度、借或贷!", vbExclamation, "凭证处理系统"
        Exit Sub
    End If
    With ListView1
        .LabelEdit = lvwManual
        .ColumnHeaders.Clear
        .ListItems.Clear
        .View = lvwReport
        .FullRowSelect = True
        .Gridlines = True
        .ColumnHeaders.Add , , "科目编码", 45
        .ColumnHeaders.Add , , "总账科目", 85
        .ColumnHeaders.Add , , "明细科目", 100
        .ColumnHeaders.Add , , "方向", 28
        If CheckBox1.Value = True Then
            .ColumnHeaders.Add , , "1月", 60
            .ColumnHeaders.Add , , "2月", 60
            .ColumnHeaders.Add , , "3月", 60
            .ColumnHeaders.Add , , "合计", 65
        End If
        If CheckBox2.Value = True Then
            .ColumnHeaders.Add , , "4月", 60
            .ColumnHeaders.Add , , "5月", 60
            .ColumnHeaders.Add , , "6月", 60
            .ColumnHeaders.Add , , "合计", 65
        End If
        If CheckBox3.Value = True Then
            .ColumnHeaders.Add , , "7月", 60
            .ColumnHeaders.Add , , "8月", 60
            .ColumnHeaders.Add , , "9月", 60
            .ColumnHeaders.Add , , "合计", 65
        End If
        If CheckBox4.Value = True Then
            .ColumnHeaders.Add , , "10月", 60
            .ColumnHeaders.Add , , "11月", 60
            .ColumnHeaders.Add , , "12月", 60
            .ColumnHeaders.Add , , "合计", 65
        End If
    End With
    Stpath = ThisWorkbook.Path & Application.PathSeparator & "分录表.mdb"
    CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath
    SQL = "select 科目编码,总账科目,明细科目,方向 from kmb where 类型='" & ComboBox2.Text & "' order by 科目编码"
    RST.Open SQL, CNN, adOpenKeyset, adLockOptimistic
    ListView1.ListItems.Clear
    M = RST.RecordCount
    PBar1.Max = M  '进度条的最大值
    For I = 1 To M
        PBar1.Value = I '进度条的动态值
        With ListView1.ListItems.Add(, , RST.Fields("科目编码"))
            .SubItems(1) = IIf(IsNull(RST.Fields("总账科目")), "", RST.Fields("总账科目"))
            .SubItems(2) = IIf(IsNull(RST.Fields("明细科目")), "", RST.Fields("明细科目"))
            .SubItems(3) = IIf(IsNull(RST.Fields("方向")), "", RST.Fields("方向"))
            col = 4          '月份从 col 列开始
            For j = 1 To 4   ''遍历 4 个季度
                If Me.Controls("CheckBox" & j).Value = True Then
                    summ = 0
                    For K = col To col + 2
                        If OptionButton1.Value = True Then
                            SSS = "借方金额"
                        End If
                        If OptionButton2.Value = True Then
                            SSS = "贷方金额"
                        End If
                        SQL = "select sum(" & SSS & ") as 月份合计 from flb "
                        SQL = SQL & " where 年=" & ComboBox1.Value & ""
                        SQL = SQL & " and 月=" & K - 3 & ""
                        SQL = SQL & " and 科目编码='" & RST.Fields("科目编码") & "'"
                        RST1.Open SQL, CNN, adOpenKeyset, adLockOptimistic
                        .SubItems(K) = Format(RST1.Fields("月份合计"), "#,##0.00")
                        summ = summ + RST1.Fields("月份合计")
                        Set RST1 = Nothing
                    Next
                    .SubItems(K) = IIf(summ = 0, "", Format(summ, "#,##0.00"))
                    col = col + 4
                End If
            Next
            RST.MoveNext
        End With
    Next
    RST.Close: RST1.Close
    CNN.Close
    Set RST = Nothing: Set CNN = Nothing
    PBar1.Value = False
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-7-6 19:03 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-7-6 21:00 | 显示全部楼层

改进:

            For j = 1 To 4   ''遍历 4 个季度
                countt = 0
                If Me.Controls("CheckBox" & j).Value = True Then
                    countt = countt + 1 '选定的季度个数
                    summ = 0
                    For K = col To col + 2
                        If OptionButton1.Value = True Then
                            SSS = "借方金额"
                        End If
                        If OptionButton2.Value = True Then
                            SSS = "贷方金额"
                        End If
                        SQL = "select sum(" & SSS & ") as 月份合计 from flb "
                        SQL = SQL & " where 年=" & ComboBox1.Value & ""
                        SQL = SQL & " and 月=" & (j - 1) * 3 + K - col + 1 & ""
                        SQL = SQL & " and 科目编码='" & RST.Fields("科目编码") & "'"
                        RST1.Open SQL, CNN, adOpenKeyset, adLockOptimistic
                        .SubItems(K) = Format(RST1.Fields("月份合计"), "#,##0.00")
                        summ = summ + RST1.Fields("月份合计")
                        Set RST1 = Nothing
                    Next
                    .SubItems(K) = IIf(summ = 0, "", Format(summ, "#,##0.00"))
                    col = col + 4
                End If
            Next

kUJBqjHF.rar (35.61 KB, 下载次数: 44)

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-7-6 21:34 | 显示全部楼层

想让合计的列着色为蓝色,以示区别。

以下的着色代码语句,如何修改?

For I = 1 To RST.RecordCount
   ......
   For J = 1 To 4   '遍历 4 个季度
   ......
      For K = col To col + 2
      ......
      Next K

      .SubItems(K) = Format(summ, "#,##0.00")
      .ListItems(I).ListSubItems(K).ForeColor = vbBlue

      ......
   Next J
Next I

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-7-6 21:36 | 显示全部楼层

可以了,原来是这样的!

.ListSubItems(K).ForeColor = vbBlue

谢谢爱歌学习!

TA的精华主题

TA的得分主题

发表于 2006-7-6 21:40 | 显示全部楼层

.SubItems(K) = IIf(summ = 0, "", Format(summ, "#,##0.00"))
                    .ListSubItems(K).ForeColor = vbBlue
                    col = col + 4
             

加在这

 

怀疑楼主大佬偷懒不动脑呀

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-24 11:37 , Processed in 0.035829 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表