Public Function getCount(sName As String)
getCount = Worksheets(sName).Range("A" & rows.count).End(xlUp).Row
End Function
Public Function getIds(sName As String) 'As Array
Application.Volatile True
Dim dic As Object, n As Integer, count As Integer, id As String
Set dic = CreateObject("Scripting.Dictionary")
count = getCount(sName)
For n = 2 To count
id = Worksheets(sName).Range("A" & n).Value
If Not dic.exists(id) Then
dic.Add id, ""
End If
Next n
getIds = dic.Keys
End Function
Public Function setSheets(arr)
Application.Volatile True
Dim s As Boolean, i As Integer, n As Integer
s = False
For i = 0 To UBound(arr)
For n = 1 To ThisWorkbook.Worksheets.count
If Sheets(n).Name = arr(i) Then
s = True
Exit For
End If
Next n
If s Then
Application.DisplayAlerts = False '删除不提示
Sheets(arr(i)).Delete
Application.DisplayAlerts = True
End If
Worksheets("审批模板").Copy after:=Sheets(Sheets.count)
Worksheets(Sheets.count).Name = arr(i)
Worksheets(arr(i)).Range("F2").Value = arr(i)
Next i
End Function
Public Function dealData(sName As String)
Dim r As Integer
r = getCount(sName)
ids = getIds(sName)
Call setSheets(ids)
For n = 2 To r
For i = 0 To UBound(ids)
If Worksheets(sName).Range("A" & n) = ids(i) Then
Worksheets(sName).Range("B" & n).Resize(1, 7).Copy
Worksheets(ids(i)).Range("A4").Insert shift:=xlDown
End If
Next i
Next n
End Function
Public Sub 计算()
Application.ScreenUpdating = False
Call dealData("事业")
Application.ScreenUpdating = True
End Sub
实现自动生成报表(vba)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 记得2010年之前,公司的项目基本上都要用到报表,以前我们常用的方法就是针对客户的需求来定制化开发(基本上是死写代...
- 今天介介绍四个简单但是很实用的VBA实例。 1、自动生成序号 输入序列的最大值,然后程序自动帮你生成所有序号。输入...