20170617xlVBA销售数据分类汇总
Public Sub SubtotalData()
AppSettings
'On Error GoTo ErrHandler
Dim StartTime, UsedTime As Variant
StartTime = VBA.Timer
'Input code here Dim Wb As Workbook
Dim Sht As Worksheet
Dim oSht As Worksheet
Dim Rng As Range
Dim Arr As Variant Const HEAD_ROW As Long = 5
Const SHEET_NAME As String = "分类汇总"
Const START_COLUMN As String = "A"
Const END_COLUMN As String = "Z" Const OTHER_HEAD_ROW As Long = 1
'Const OTHER_SHEET_NAME As String = "DATA"
Dim DataName As String
Const OTHER_START_COLUMN As String = "A"
Const OTHER_END_COLUMN As String = "Z" Dim Client As String '客户名称
Dim BookNo As String '订单号
Dim Status As String '状态
Dim Item As String '统计项目
Dim dClient As Object
Dim dBookInfo As Object
Dim MixKey As String
Dim Key As String
Dim TmpKey As String
Dim OneClient
Dim Index As Long Set dBookNo = CreateObject("Scripting.Dictionary")
Set dBookInfo = CreateObject("Scripting.Dictionary")
Set dClient = CreateObject("Scripting.Dictionary") Set Wb = Application.ThisWorkbook
Set Sht = Wb.Worksheets(SHEET_NAME)
With Sht
.UsedRange.Offset(HEAD_ROW).ClearContents
DataName = .Range("L2").Value
End With If DataName = "" Then
MsgBox "请输入查询范围!", vbInformation, "QQ "
GoTo ErrorExit
End If If DataName <> "全年" Then
'判断某个月的!
On Error Resume Next
Set oSht = Wb.Worksheets(DataName)
If oSht Is Nothing Then
MsgBox "输入的月份(工作表名)有误,请重新输入!", vbInformation, "QQ "
GoTo ErrorExit
End If With oSht EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range(.Cells(OTHER_HEAD_ROW + 1, "A"), .Cells(EndRow, "Y"))
'Debug.Print Rng.Address
Arr = Rng.Value For i = LBound(Arr) To UBound(Arr)
Client = CStr(Arr(i, 2)) '客户名称 BookNo = CStr(Arr(i, 1))
Status = CStr(Arr(i, 6)) '进度状态 dClient(Client) = "" '保存所有客户名称 MixKey = Client & ";" & BookNo & ";" & Status
Key = Client & ";" & Status '客户,状态 If dBookNo.Exists(MixKey) = False Then '防止重复
TmpKey = Key & ";" & "定单量"
' dBookCount(TmpKey) = dBookCount(TmpKey) + 1
dBookInfo(TmpKey) = dBookInfo(TmpKey) + 1
dBookNo(MixKey) = "" '记下订单号,防止重复
End If TmpKey = Key & ";" & "订单金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 12) TmpKey = Key & ";" & "已收款金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 13) TmpKey = Key & ";" & "出库金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 14) TmpKey = Key & ";" & "未收款金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 15) Next i
End With Else For Each oSht In Wb.Worksheets
If oSht.Name Like "*月" Then
With oSht EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range(.Cells(OTHER_HEAD_ROW + 1, "A"), .Cells(EndRow, "Y"))
'Debug.Print Rng.Address
Arr = Rng.Value For i = LBound(Arr) To UBound(Arr)
Client = CStr(Arr(i, 2)) '客户名称 BookNo = CStr(Arr(i, 1))
Status = CStr(Arr(i, 6)) '进度状态 dClient(Client) = "" '保存所有客户名称 MixKey = Client & ";" & BookNo & ";" & Status
Key = Client & ";" & Status '客户,状态 If dBookNo.Exists(MixKey) = False Then '防止重复
TmpKey = Key & ";" & "定单量"
' dBookCount(TmpKey) = dBookCount(TmpKey) + 1
dBookInfo(TmpKey) = dBookInfo(TmpKey) + 1
dBookNo(MixKey) = "" '记下订单号,防止重复
End If TmpKey = Key & ";" & "订单金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 12) TmpKey = Key & ";" & "已收款金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 13) TmpKey = Key & ";" & "出库金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 14) TmpKey = Key & ";" & "未收款金额"
dBookInfo(TmpKey) = dBookInfo(TmpKey) + Arr(i, 15) Next i
End With End If
Next oSht
End If With Sht
Index = 0
For Each OneClient In dClient.keys
Index = Index + 1
.Cells(HEAD_ROW + Index, 1).Value = Index
.Cells(HEAD_ROW + Index, 2).Value = OneClient For j = 3 To 12
Status = .Cells(HEAD_ROW - 1, j).MergeArea.Cells(1, 1).Value
Item = .Cells(HEAD_ROW, j).Value
TmpKey = OneClient & ";" & Status & ";" & Item
' Debug.Print TmpKey
.Cells(HEAD_ROW + Index, j).Value = dBookInfo(TmpKey)
'Debug.Print Status
Next j
Next OneClient SetEdges Application.Intersect(.UsedRange.Offset(HEAD_ROW), .UsedRange)
End With UsedTime = VBA.Timer - StartTime
Debug.Print "UsedTime:" & Format(UsedTime, "0.000 Seconds")
'MsgBox "UsedTime:" & Format(UsedTime, "0.000 Seconds"), vbOKOnly, "NextSeven QQ "
ErrorExit:
AppSettings False
Exit Sub
ErrHandler:
If Err.Number <> 0 Then
MsgBox Err.Description & "!", vbCritical, "NextSeven "
Debug.Print Err.Description
Err.Clear
Resume ErrorExit
End If
End Sub Public Sub AppSettings(Optional IsStart As Boolean = True)
If IsStart Then
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Application.StatusBar = ">>>>>>>>Macro Is Running>>>>>>>>"
Else
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Application.StatusBar = False
End If
End Sub Private Sub SetEdges(ByVal Rng As Range)
With Rng
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
If .Cells.Count > 1 Then
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
End With
End Sub
20170617xlVBA销售数据分类汇总的更多相关文章
- [置顶]生鲜配送管理系统_升鲜宝V2.0 销售订单汇总_采购任务分配功能_操作说明
做好生鲜供应链系统,要注意三个方面,1.分拣 2 采购 3 库存,市面上做的比较成熟的功能,还是分拣这一块(按客户分拣.按订单分拣.按商品分类分拣.按商品分拣.按线路分拣.客户自由组合分拣)[下篇文 ...
- python 数据分类汇总
STEP1: #读取数据: import pandas as pdinputfile_1 = "F:\\大论文实验\\数据处理\\贫困人口数据_2015.xlsx" data1 = ...
- order_by_、group_by_、having的用法区别
写于 2012-11-20 22:14 doc文档上. Having 这个是用在聚合函数的用法.当我们在用聚合函数的时候,一般都要用到GROUP BY 先进行分组,然后再进行聚合函数的运算.运算完后 ...
- SQL 笔记 By 华仔
-------------------------------------读书笔记------------------------------- 笔记1-徐 最常用的几种备份方法 笔记2-徐 收缩数据 ...
- Excel与Word套打功能使用技巧及EXCEL数据处理成绩
Excel与Word套打功能使用技巧 婚礼邀请友人参加,就需要写请柬.而且写请柬不但要求字写得端正,还不能有错别字,再加上邀请的朋友多,写请柬就是一个劳累活.这时我们利用Word的套打功能,就会让写请 ...
- BIEEE 创建多维钻取分析(4)
在上一节时,我们创建了一个基于部门号的工资分类汇总. 这里就引出了一个概念:维度 专业的解释大家自行百度,这里就不班门弄斧了.从数据的使用角度看,维度可以简单的理解成“数据分类汇总的一种依据”. 按“ ...
- MorningSale 介绍
MorningSale是一个WEB端的收集门店销售数据,显示销售数据的简单系统,我相信该系统能够有效的提高销售公司在门店销售数据收集 汇总 分析方面的工作效率. 主要功能介绍如下: 1.查看某个店面 ...
- ABAP开发基础知识:内表(Internal Table)
http://www.cnblogs.com/foxting/archive/2012/03/19/2406830.html 内表与结构体基本类似,它同样是程序运行中被临时创建的一个存储空间,它是一个 ...
- 不用Google Adsense的84个赚钱方法
这是一个关于网络广告商和网络销售的汇总列表,可以用来为您的网站或博客赚点钱.广告商都是英文的,加入广告请确认其是否支持中国地区支持,不支持的话就不必加入了. Chitika : 购物中心旗帜广告. ( ...
随机推荐
- centos7.3安装redis
yum install epel-release yum install redis 如果支持从其他机器能访问,需要修改配置文件 /etc/redis.conf,注释掉 bin 127.0.0.1 如 ...
- Linux基础命令---comm
comm 逐行比较两个已经排序过的文件.结果以3列显示:第1列显示只在file1出现的内容,第2列显示只在file2出现的内容,第3列显示同时出现的内容. 此命令的适用范围:RedHat.RHEL.U ...
- linux服务器文件索引inodes满了
inode节点中,记录了文件的类型.大小.权限.所有者.文件连接的数目.创建时间与更新时间等重要的信息,还有一个比较重要的内容就是指向数据块的指针.一般情况不需要特殊配置,如果存放文件很多,需要配置. ...
- python之路----hashlib模块
在平时生活中,有很多情况下,你在不知不觉中,就用到了hashlib模块,比如:注册和登录认证注册和登录认真过程,就是把注册用的账户密码进行:加密 --> 解密 的过程,在加密.解密过程中,用的了 ...
- 计算概论(A)/基础编程练习1(8题)/5:鸡兔同笼
#include<stdio.h> int main() { // 鸡兔同笼中脚的总数:a < 32768 int a; scanf("%d", &a); ...
- php检查是否是数字和字母
/* 检查是否是数字和字母* php内置函数ctype_alnum检查字符串是否是数字和字母,或者两者混合* $string*/ public function is_numandlitter($st ...
- STM32.SPI(25Q16)
1.首先认识下W25Q16DVSIG, SOP8 SPI FLASH 16MBIT 2MB(4096个字节) (里面可以放字库,图片,也可以程序掉电不丢失数据放里面) 例程讲解: ① 1.用到SPI ...
- arm linux下启动ftp服务
1.环境: /home/jello # uname -aLinux 3.10.0 #2 SMP Mon Mar 6 17:52:09 CST 2017 armv7l GNU/Linux 2.使用tc ...
- 51nod 1020 逆序排列 递推DP
1020 逆序排列 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么 ...
- yarn虚拟cpu和虚拟内存
虚拟cpu 虚拟的cpu代码并发数,如果一个container拥有2个vcpu,那么该container就可以真正的在同一时间运行两个线程,而不是靠切时间片而达到的逻辑并发.所以一般虚拟的cpu需要和 ...