20170612xlVBA多文件多类别分类求和匹配
Public Sub Basic_CodeFrame()
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 OpenWb As Workbook
Dim OpenSht As Worksheet
Dim NewWb As Workbook
Dim NewSht As Worksheet
Dim Arr As Variant
Dim i As Long, j As Long
Dim EndRow As Long
Dim Brr()
Dim Crr()
Dim Drr()
Dim Index As Long
Dim Index1 As Long
Dim Index2 As Long
Dim OneKey As Variant Dim Title As Variant Dim FolderPath As String
Const FolderName As String = "原始文件"
Const OutPutName As String = "结果文件" Const OpFile1 As String = "台面补货d.xlsx"
Const OpFile2 As String = "品牌补货d.xlsx"
Const OpFile3 As String = "小类补货d.xlsx" Dim OpPath As String Const AName As String = "盘点"
Dim aFile As String, aPath As String
Const CName As String = "产品资料"
Dim cFile As String, cPath As String
Const BName As String = "库存"
Dim bFile As String, bPath As String
Const DName As String = "销售"
Dim dFile As String, dPath As String Dim aInfo(1 To 4) As Object
Dim bInfo(1 To 4) As Object
Dim cInfo(1 To 18) As Object
Dim dInfo(1 To 5) As Object
Dim dCate As Object '小类
Dim dBrand As Object '品牌
Dim Cate As String
Dim Brand As String
Set dCate = CreateObject("Scripting.Dictionary")
Set dBrand = CreateObject("Scripting.Dictionary") Set Wb = Application.ThisWorkbook
Set Sht = Wb.Worksheets("标题")
Title = Sht.Range("A1:X1").Value
FolderPath = Wb.Path & Application.PathSeparator & _
FolderName & Application.PathSeparator '先到C表保存各种字段信息 For j = 1 To 18
Set cInfo(j) = CreateObject("Scripting.Dictionary")
Next j cFile = Dir(FolderPath & "*" & CName & "*.xls*")
cPath = FolderPath & cFile
Debug.Print cPath Set OpenWb = Application.Workbooks.Open(cPath)
Set OpenSht = OpenWb.Worksheets(1)
With OpenSht
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range("A2:R" & EndRow)
Arr = Rng.Value
For i = LBound(Arr) To UBound(Arr)
Key = CStr(Arr(i, 1))
Key = Replace(Key, " ", "")
For j = LBound(Arr, 2) To UBound(Arr, 2)
cInfo(j)(Key) = Arr(i, j)
Next j
Next i
End With
Set OpenSht = Nothing
OpenWb.Close False '再到A表读取报货单
For j = 1 To 4
Set aInfo(j) = CreateObject("Scripting.Dictionary")
Next j aFile = Dir(FolderPath & "*" & AName & "*.xls*")
aPath = FolderPath & aFile
Debug.Print aPath Set OpenWb = Application.Workbooks.Open(aPath)
Set OpenSht = OpenWb.Worksheets(1) With OpenSht
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range("A2:D" & EndRow)
Arr = Rng.Value For i = LBound(Arr) To UBound(Arr)
Key = CStr(Arr(i, 1))
Key = Replace(Key, " ", "")
For j = LBound(Arr, 2) To UBound(Arr, 2)
aInfo(j)(Key) = Arr(i, j)
Next j
Next i End With
Set OpenSht = Nothing
OpenWb.Close False '再到B表读取库存
For j = 1 To 4
Set bInfo(j) = CreateObject("Scripting.Dictionary")
Next j bFile = Dir(FolderPath & "*" & BName & "*.xls*")
bPath = FolderPath & bFile
Debug.Print bPath Set OpenWb = Application.Workbooks.Open(bPath)
Set OpenSht = OpenWb.Worksheets(1) With OpenSht
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range("A2:D" & EndRow)
Arr = Rng.Value For i = LBound(Arr) To UBound(Arr)
Key = CStr(Arr(i, 1))
Key = Replace(Key, " ", "")
For j = LBound(Arr, 2) To UBound(Arr, 2)
bInfo(j)(Key) = Arr(i, j)
Next j
Next i End With
Set OpenSht = Nothing
OpenWb.Close False '再到D表读取销售
For j = 1 To 5
Set dInfo(j) = CreateObject("Scripting.Dictionary")
Next j dFile = Dir(FolderPath & "*" & DName & "*.xls*")
dPath = FolderPath & dFile
Debug.Print dPath Set OpenWb = Application.Workbooks.Open(dPath)
Set OpenSht = OpenWb.Worksheets(1) With OpenSht
EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row
Set Rng = .Range("A2:D" & EndRow)
Arr = Rng.Value For i = LBound(Arr) To UBound(Arr)
Key = CStr(Arr(i, 1))
Key = Replace(Key, " ", "")
For j = LBound(Arr, 2) To UBound(Arr, 2)
dInfo(j)(Key) = Arr(i, j)
Next j
Next i End With
Set OpenSht = Nothing
OpenWb.Close False '保存上报品牌与小类
'For Each OneKey In aInfo(1).keys
'Brand = cInfo(6)(OneKey) '保存品牌
'dBrand(Brand) = ""
'Cate = cInfo(4)(OneKey) '保存小类
'dCate(Cate) = ""
'Next OneKey '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '计算台面补货
ReDim Brr(1 To 24, 1 To 1)
Index = 0
For Each OneKey In aInfo(1).keys
Index = Index + 1
ReDim Preserve Brr(1 To 24, 1 To Index)
Brr(1, Index) = OneKey & " " '条码
Brr(2, Index) = cInfo(2)(OneKey) '商品名称2
Brr(3, Index) = IIf(aInfo(4)(OneKey) = "", 0, aInfo(4)(OneKey)) '商场库存4
Brr(4, Index) = IIf(bInfo(3)(OneKey) = "", 0, bInfo(3)(OneKey)) '总部库存3
Brr(5, Index) = IIf(dInfo(3)(OneKey) = "", 0, dInfo(3)(OneKey)) '销售数量3
Brr(6, Index) = cInfo(6)(OneKey) '品牌6
Brr(7, Index) = cInfo(4)(OneKey) '小类4 Brand = cInfo(6)(OneKey) '保存品牌
dBrand(Brand) = ""
Cate = cInfo(4)(OneKey) '保存小类
dCate(Cate) = "" Brr(8, Index) = (Brr(5, Index) - Brr(3, Index)) * 1.5 '(D-A)*1.5 要出多少货
If Brr(8, Index) > 0 Then
If Brr(4, Index) >= Brr(8, Index) Then '库存足够出货
Brr(9, Index) = Brr(8, Index) '直接出货
Brr(10, Index) = "" '无需采购
Else
Brr(9, Index) = Brr(4, Index) '库存全出
Brr(10, Index) = Brr(8, Index) - Brr(4, Index) '计算采购
End If
End If
'------
Brr(11, Index) = cInfo(3)(OneKey) '大类
Brr(12, Index) = cInfo(5)(OneKey) '规格
For j = 1 To 12
Brr(j + 12, Index) = cInfo(j + 6)(OneKey)
Next j
Next OneKey '创建台面补货文件
OpPath = Wb.Path & "\" & OutPutName & "\" & Replace(OpFile1, "d", "-" & Split(dFile, ".")(0))
Debug.Print OpPath Set NewWb = Application.Workbooks.Add()
Set NewSht = NewWb.Worksheets(1)
NewSht.Name = Split(OpFile1, "d")(0)
NewWb.SaveAs OpPath
With NewSht
.Columns("A:A").NumberFormat = "@"
.Range("A1:X1").Value = Title
.Range("a2").Resize(Index, 24).Value = _
Application.WorksheetFunction.Transpose(Brr)
End With NewWb.Close True
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '计算品牌与小类补货
ReDim Crr(1 To 24, 1 To 1)
ReDim Drr(1 To 24, 1 To 1) Index1 = 0
Index2 = 0
For Each OneKey In cInfo(1).keys Brand = cInfo(6)(OneKey) '保存品牌
If dBrand.Exists(Brand) Then '属于改品牌
Index1 = Index1 + 1
ReDim Preserve Crr(1 To 24, 1 To Index1)
Crr(1, Index1) = OneKey & " " '条码
Crr(2, Index1) = cInfo(2)(OneKey) '商品名称2
Crr(3, Index1) = IIf(aInfo(4)(OneKey) = "", 0, aInfo(4)(OneKey)) '商场库存4
Crr(4, Index1) = IIf(bInfo(3)(OneKey) = "", 0, bInfo(3)(OneKey)) '总部库存3
Crr(5, Index1) = IIf(dInfo(3)(OneKey) = "", 0, dInfo(3)(OneKey)) '销售数量3
Crr(6, Index1) = cInfo(6)(OneKey) '品牌6
Crr(7, Index1) = cInfo(4)(OneKey) '小类4
Crr(8, Index1) = (Crr(5, Index1) - Crr(3, Index1)) * 1.5 '(D-A)*1.5 要出多少货
If Crr(8, Index1) > 0 Then
If Crr(4, Index1) >= Crr(8, Index1) Then '库存足够出货
Crr(9, Index1) = Crr(8, Index1) '直接出货
Crr(10, Index1) = "" '无需采购
Else
Crr(9, Index1) = Crr(4, Index1) '库存全出
Crr(10, Index1) = Crr(8, Index1) - Crr(4, Index1) '计算采购
End If
End If
'------
Crr(11, Index1) = cInfo(3)(OneKey) '大类
Crr(12, Index1) = cInfo(5)(OneKey) '规格
For j = 1 To 12
Crr(j + 12, Index1) = cInfo(j + 6)(OneKey)
Next j
End If
Cate = cInfo(4)(OneKey) '保存小类
If dCate.Exists(Cate) Then
Index2 = Index2 + 1
ReDim Preserve Drr(1 To 24, 1 To Index2)
Drr(1, Index2) = OneKey & " " '条码
Drr(2, Index2) = cInfo(2)(OneKey) '商品名称2
Drr(3, Index2) = IIf(aInfo(4)(OneKey) = "", 0, aInfo(4)(OneKey)) '商场库存4
Drr(4, Index2) = IIf(bInfo(3)(OneKey) = "", 0, bInfo(3)(OneKey)) '总部库存3
Drr(5, Index2) = IIf(dInfo(3)(OneKey) = "", 0, dInfo(3)(OneKey)) '销售数量3
Drr(6, Index2) = cInfo(6)(OneKey) '品牌6
Drr(7, Index2) = cInfo(4)(OneKey) '小类4
Drr(8, Index2) = (Drr(5, Index2) - Drr(3, Index2)) * 1.5 '(D-A)*1.5 要出多少货
If Drr(8, Index2) > 0 Then
If Drr(4, Index2) >= Drr(8, Index2) Then '库存足够出货
Drr(9, Index2) = Drr(8, Index2) '直接出货
Drr(10, Index2) = "" '无需采购
Else
Drr(9, Index2) = Drr(4, Index2) '库存全出
Drr(10, Index2) = Drr(8, Index2) - Drr(4, Index2) '计算采购
End If
End If
'------
Drr(11, Index2) = cInfo(3)(OneKey) '大类
Drr(12, Index2) = cInfo(5)(OneKey) '规格
For j = 1 To 12
Drr(j + 12, Index2) = cInfo(j + 6)(OneKey)
Next j
End If Next OneKey '创建品牌补货文件
OpPath = Wb.Path & "\" & OutPutName & "\" & Replace(OpFile2, "d", "-" & Split(dFile, ".")(0))
Debug.Print OpPath Set NewWb = Application.Workbooks.Add()
Set NewSht = NewWb.Worksheets(1)
NewSht.Name = Split(OpFile2, "d")(0)
NewWb.SaveAs OpPath
With NewSht
.Columns("A:A").NumberFormat = "@"
.Range("A1:X1").Value = Title
.Range("a2").Resize(Index, 24).Value = _
Application.WorksheetFunction.Transpose(Crr)
End With NewWb.Close True '创建小类补货文件
OpPath = Wb.Path & "\" & OutPutName & "\" & Replace(OpFile3, "d", "-" & Split(dFile, ".")(0))
Debug.Print OpPath Set NewWb = Application.Workbooks.Add()
Set NewSht = NewWb.Worksheets(1)
NewSht.Name = Split(OpFile3, "d")(0)
NewWb.SaveAs OpPath
With NewSht
.Columns("A:A").NumberFormat = "@"
.Range("A1:X1").Value = Title
.Range("a2").Resize(Index, 24).Value = _
Application.WorksheetFunction.Transpose(Drr)
End With NewWb.Close True UsedTime = VBA.Timer - StartTime
'Debug.Print "UsedTime:" & Format(UsedTime, "0.000 Seconds")
MsgBox "UsedTime:" & Format(UsedTime, "0.000 Seconds"), vbOKOnly, "NS QQ "
ErrorExit:
AppSettings False
Exit Sub
ErrHandler:
If Err.Number <> 0 Then
MsgBox Err.Description & "!", vbCritical, "NS QQ "
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
20170612xlVBA多文件多类别分类求和匹配的更多相关文章
- 关于ios object-c 类别-分类 category 的静态方法与私有变量,协议 protocol
关于ios object-c 类别-分类 category 的静态方法与私有变量,协议 protocol 2014-02-18 19:57 315人阅读 评论(0) 收藏 举报 1.category, ...
- Atitit 基于图片图像 与文档混合文件夹的分类
Atitit 基于图片图像 与文档混合文件夹的分类 太小的文档(txt doc csv exl ppt pptx)单独分类 Mov10KminiDoc 但是可能会有一些书法图片迁移,因为他们很微小,需 ...
- Linux下find一次查找多个指定类型文件,指定文件或者排除某类文件,在 GREP 中匹配多个关键 批量修改文件名等
http://blog.sina.com.cn/s/blog_62e7fe670101dg9d.html linux下二进制文件查找: strings 0000.ts | grep -o " ...
- [DeeplearningAI笔记]Multi-class classification多类别分类Softmax regression_02_3.8-3.9
Multi-class classification多类别分类 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.8 Softmax regression 原有课程我们主要介绍的是二分分类( ...
- Excel技巧--分类求和与空白批量填充
分类求和: 当我们要对以上多个分类空白求和时,可以巧用Alt+=键: 1.选择对应要求和的列: 2.点击“查找与选择”下拉列,选择“定位条件”,对话框选择“空值”,点确定.将列中的空白单元格选好: 3 ...
- OC的类别(分类)和拓展
一.分类: 1.适用范围 当你已经封装好了一个类(也可能是系统类.第三方库),不想在改动这个类了,可是随着程序功能的增加需要在类中增加一个方法,这时我们不必修改主类,只需要给你原来的类增加一 ...
- shell脚本(傻瓜式处理文件到指定分类)
前言 每一到两周,我大概会新增十多个甚至更多的资料文件,都是些最近遇到的一些问题的总结或者相关技术文档,但是资料都是在公司电脑上,拷贝到自己电脑上后,又得一个个去找一个这个应该放到哪个分类,个人感觉很 ...
- Codeigniter文件上传类型不匹配错误
Codeigniter的文件上传类方便了我们使用PHP来处理文件上传的操作,使用起来非常简单,如下: $config['upload_path'] = './uploads/'; $config[ ...
- IE9以上 CSS文件因Mime类型不匹配而被忽略 其他浏览器及IE8以下显示正常
什么是Mime类型? MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名 ...
随机推荐
- python print 使用分隔符 或行尾符
使用print() 函数输出数据,但是想改变默认的分隔符或者行尾符. >>> print('ACME', 50, 91.5) ACME 50 91.5 >>> pr ...
- 【转】Java学习:Java中的线程之线程间的通信
hello各位小伙伴 今天我们来搞一下 线程之间的通信 ( • ̀ω•́ )✧ 让线程按照我们的想法来执行 两个线程间的通信 这是我们之前的线程. 执行效果:谁抢到资源,谁运行~ 实现线程交替执行: ...
- python的数据结构之数字和字符串(四)
一.数字 Python Number 数据类型用于存储数值.数据类型是不允许改变的,这就意味着如果改变 Number 数据类型的值,将重新分配内存空间. Python 支持四种不同的数值类型: 整型( ...
- EasyUI+bootsrtap混合前端框架
EasyUI+bootsrtap混合前端框架 http://www.jeasyui.com/download/index.php用户没有登录前浏览的页面用bootsrtap框架用户登录进去后的商家管理 ...
- MySQL数据库----存储过程
存储过程 存储过程包含了一系列可执行的sql语句,存储过程存放于MySQL中,通过调用它的名字可以执行其内部的一堆sql -- 存储过程的优点: -- 1.程序与数据实现解耦 -- 2.减少网络传输的 ...
- cursor图标自定义
cursor: url(./images/favicon.ico), auto; 首先auto必须加上,其次必须使用ico文件,目前来说ico文件没有兼容性问题,ico格式怎么转? 传送门:http: ...
- pyDay4
内容来自廖雪峰的官方网站 1.关键字参数有什么用?它可以扩展函数的功能. 2.参数定义的顺序必须是:必选参数.默认参数.可变参数.命名关键字参数和关键字参数. 3.对于任意函数,都可以通过类似func ...
- SIFT特征原理简析(HELU版)
SIFT(Scale-Invariant Feature Transform)是一种具有尺度不变性和光照不变性的特征描述子,也同时是一套特征提取的理论,首次由D. G. Lowe于2004年以< ...
- Fast特征点的寻找和提取
一.基础 最初由Rosten和Drummond [Rosten06]提出的FAST(加速段测试的特征)特征检测算法是基于将点P与其包围圆内的点集的直接比较的思想. 基本思想是,如果附近的几个点与P类似 ...
- 2019“嘉韦思”杯RSA256题目wp
首先我们从网站下载了一个压缩包,解压出来一看里面有2个文件 首先我们先打开fllllllag康康,结果发现是一串乱码,这时候第一反应就是,文件被加密了,再看fllllllag下面的gy.key文件,更 ...