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 : 购物中心旗帜广告. ( ...
随机推荐
- yum安装时提示app is currently holding the yum lock; waiting for it to exit
yum安装时出现下面情况 可能是yum升级一些文件时,出现这种情况 解决方法: #rm -f /var/run/yum.pid 强制关掉yun进程
- 关于Context []startup failed due to previous errors
文章转自:http://blog.sina.com.cn/s/blog_49b4a1f10100q93e.html 框架搭建好后,启动服务器出现如下的信息: log4j:WARN No appende ...
- redis安装 phpredis Jedis 扩展的实现及注意事项,php,java,python相关插件安装实例代码和文档推荐
redis安装 phpredis Jedis 扩展的实现及注意事项,php,java,python相关插件安装实例代码和文档推荐 1.Redis 官方网站下载: http://redis.io/dow ...
- java.lang.NoClassDefFoundError: org/apache/http/client/config/RequestConfig
java 错误.java.lang.NoClassDefFoundError: org/apache/http/client/config/RequestConfig 本质上是httpClient的j ...
- 【运维技术】JENKINS管道部署容器化初探
目标服务器安装docker参考官方文档 https://docs.docker.com/install/linux/docker-ce/centos/ (可选)在目标服务器上安装docker私服 ht ...
- win7 安装.Net framework 4.0出现 安装不成功,错误代码0x80240037 的解决方法
1.安装说明 系统:win7 64位 安装包:dotNetFx40_Full_x86_x64.exe(.Net framework 4.0) 出现的问题:在win7 上安装dotNetFx40_Ful ...
- Android http通信 HttpURLConnection
post 请求: package com.example.administrator.eschool; import android.os.Bundle; import android.os.Hand ...
- sql注入学习心得与sqlmap使用心得
做题是最好的老师 首先先来分享一下我用来练手的题目,实验吧中的简单的sql注入1,2,3 不得不说,sql注入真是一个神奇的东西,至少我以前看起来一点头绪都没有的题目能入手了 首先是简单的sql注入3 ...
- Python3基础 print \n换行
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- U盘+GRUB2引导PE或linux镜像
利用U盘制作启动盘,引导WinPE.Linux安装的文章多如牛毛,与他们相比本文的特点有: 1.用且仅用grbu2做引导.不使用grub4dos,不是使用msdos mbr转到活动分区,到ntldr, ...