Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1185|回复: 0

按日期查找多列和统计,

[复制链接]
发表于 2016-1-19 21:49 | 显示全部楼层 |阅读模式
求大师帮我看下这个代码怎么改,谢谢了
Private Sub CommandButton3_Click()
    Dim SQL As String, h, j, x, y

    Me.ListView1.ListItems.Clear
    Set RST = New ADODB.Recordset
    If ComboBox4.ListIndex = -1 Then
       SQL = " select 区域,sum(数量) as 数量 ,类别 ,姓名 from 申请资料  where 申请日期 between #" & DTPicker1 & "# AND " & "#" & DTPicker2 & "# group by 区域"
    Else
        SQL = " select 区域,sum(数量) as 数量 ,类别 ,姓名 from 申请资料  where 申请日期 between #" & DTPicker1 & "# AND " & "#" & DTPicker2 & "# and 区域='" & ComboBox4.Value & "' group by 区域"
    End If
    RST.Open SQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText
    iCount = RST.RecordCount
    For i = 1 To iCount

        ListView1.ListItems.Add , , RST.Fields("区域")
        ListView1.ListItems(i).SubItems(1) = RST.Fields("姓名")
        ListView1.ListItems(i).SubItems(2) = RST.Fields("类别")
        ListView1.ListItems(i).SubItems(3) = RST.Fields("数量")
        RST.MoveNext
    Next i
End Sub

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2025-8-16 05:24 , Processed in 0.086784 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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