ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 25277|回复: 42

[分享] 动态生成车间生产日报表

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2013-5-31 12:38 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
车间生产日报表.zip (4.13 KB, 下载次数: 5554)

最近,为了验厂,人事要我准备3个月的车间生产日报表,但我们车间根本就没有记录,怎么办?人事要我瞎编,但如果用手工写的话,估计要累死,本人从来不喜欢做这种重复又很累的工作,于是花了一晚上的时间,写成了这个程序,几分钟就生成了三个月的车间生产日报表,附件是车间生产日报表的模板!
[code=vb]
Private Sub Command1_Click()
Dim MyExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlSheet1 As Excel.Worksheet
Dim i As Long
Dim j As Long
Dim x As Integer
Dim y As Integer
Dim dx As Integer
Dim cl As Integer
Dim jwz As Integer
Dim yb As Integer
Dim gx(1 To 4) As String '工序
gx(1) = "包装"
gx(2) = "磨光"
gx(3) = "钻床"
gx(4) = "油机"
Set MyExcel = CreateObject("Excel.Application")
MyExcel.Visible = False
Set xlBook = MyExcel.Workbooks.Open("F:\车间生产日报表.xls")
Set xlSheet = xlBook.Sheets("Sheet1")
Set xlSheet1 = xlBook.Sheets("Sheet2")
For i = 1 To 68
xlSheet.Range("a1:h31").Copy Destination:=xlSheet.Range("a" & i * 31 + 1)
Next
j = xlSheet.Range("a65536").End(xlUp).Row
For i = 1 To j
xlSheet.Rows(i).RowHeight = 21
Next
For i = 0 To 69
xlSheet.Rows(i * 31 + 1).RowHeight = 48
Next
Dim arr(1 To 29, 1 To 7) As String
Dim arru(1 To 29) As Boolean
Dim jx As Boolean
Dim arrd(1 To 69) As String
For i = 1 To 29
arr(i, 1) = xlSheet1.Cells(i, 1).Value
arr(i, 2) = xlSheet1.Cells(i, 2).Value
arr(i, 3) = xlSheet1.Cells(i, 3).Value
arr(i, 4) = xlSheet1.Cells(i, 4).Value * 2
arr(i, 5) = xlSheet1.Cells(i, 4).Value * 3
arr(i, 6) = xlSheet1.Cells(i, 4).Value * 3
arr(i, 7) = xlSheet1.Cells(i, 4).Value * 3
Next
For i = 1 To 69
arrd(i) = xlSheet1.Cells(i, 5).Value
Next
For i = 1 To 69
jwz = (i - 1) * 31 + 4
jwz1 = 0
xlSheet.Cells(jwz - 2, 6).Value = arrd(i)
xlSheet.Cells(jwz + 27, 1).Value = IIf(i < 48, "填表:XXX", "填表:YYY")
For j = 1 To 29
arru(j) = False
Next
For j = 1 To 4

yb = Int(Rnd * 2) + 1
For x = 1 To yb
Randomize
cl = Int(Rnd * 100) + IIf(j = 1, 135, 255) + IIf(j = 1, Int(i / 30 * 80), Int(i / 30 * 150))
For y = 1 To 26
If arru(y + j - 1) = False Then
If arr(y + j - 1, j + 3) - 58 >= cl Then
xlSheet.Cells(jwz + x - 1 + jwz1, 1).Value = arr(y + j - 1, 1)
xlSheet.Cells(jwz + x - 1 + jwz1, 3).Value = arr(y + j - 1, 2)
xlSheet.Cells(jwz + x - 1 + jwz1, 4).Value = arr(y + j - 1, 3)
xlSheet.Cells(jwz + x - 1 + jwz1, 5).Value = gx(j)
xlSheet.Cells(jwz + x - 1 + jwz1, 6).Value = cl
arr(y + j - 1, j + 3) = arr(y + j - 1, j + 3) - cl
arru(y + j - 1) = True
Exit For
End If
If arr(y + j - 1, j + 3) > 0 Then
xlSheet.Cells(jwz + x - 1 + jwz1, 1).Value = arr(y + j - 1, 1)
xlSheet.Cells(jwz + x - 1 + jwz1, 3).Value = arr(y + j - 1, 2)
xlSheet.Cells(jwz + x - 1 + jwz1, 4).Value = arr(y + j - 1, 3)
xlSheet.Cells(jwz + x - 1 + jwz1, 5).Value = gx(j)
xlSheet.Cells(jwz + x - 1 + jwz1, 6).Value = arr(y + j - 1, j + 3)
arr(y + j - 1, j + 3) = 0
arru(y + j - 1) = True
Exit For
End If
End If
Next
Next
jwz1 = jwz1 + yb
Next
Next
xlBook.Save
xlBook.Close
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlSheet1 = Nothing
Set MyExcel = Nothing
MsgBox "ok"
End Sub
Private Sub Command2_Click()
Dim MyExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlBook3 As Excel.Workbook
Dim xlBook4 As Excel.Workbook
Dim xlBook5 As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlSheetN As Excel.Worksheet
Dim i As Integer
Dim m As Integer
Set MyExcel = CreateObject("Excel.Application")
MyExcel.Visible = False
Set xlBook = MyExcel.Workbooks.Open("F:\车间生产日报表.xls")
Set xlBook3 = MyExcel.Workbooks.Open("F:\3月份车间生产日报表.xls")
Set xlBook4 = MyExcel.Workbooks.Open("F:\4月份车间生产日报表.xls")
Set xlBook5 = MyExcel.Workbooks.Open("F:\5月份车间生产日报表.xls")
Set xlSheet = xlBook.Sheets("Sheet1")
For i = 0 To 67
m = Month(xlSheet.Cells(i * 31 + 2, 6).Value)
If m = 3 Then
Set xlSheetN = xlBook3.Worksheets.Add
xlSheetN.Name = xlSheet.Cells(i * 31 + 2, 6).Value
End If
If m = 4 Then
Set xlSheetN = xlBook4.Worksheets.Add
xlSheetN.Name = xlSheet.Cells(i * 31 + 2, 6).Value
End If
If m = 5 Then
Set xlSheetN = xlBook5.Worksheets.Add
xlSheetN.Name = xlSheet.Cells(i * 31 + 2, 6).Value
End If
xlSheet.Range("a" & (i * 31 + 1) & ":h" & (i + 1) * 31).Copy Destination:=xlSheetN.Range("a1:h31")
Next
xlBook3.Save
xlBook4.Save
xlBook5.Save
Set xlBook3 = Nothing
Set xlBook4 = Nothing
Set xlBook5 = Nothing
Set xlSheetN = Nothing
Set xlSheet = Nothing
Set MyExcel = Nothing
MsgBox "ok"
End Sub

[/code]

TA的精华主题

TA的得分主题

发表于 2013-5-31 13:19 | 显示全部楼层
好贴,下载学习了,努力奋斗中

TA的精华主题

TA的得分主题

发表于 2013-6-4 20:03 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-6-4 20:45 | 显示全部楼层
晕!excel还能造假!{:soso_e128:}

TA的精华主题

TA的得分主题

发表于 2013-10-30 12:58 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-11-21 11:07 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-11-21 12:27 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-12-29 13:53 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-12-29 15:08 | 显示全部楼层
楼主很强大,学习了,效率是杠杠的。巧妙,造假原来也可以这么简单{:soso_e113:}

TA的精华主题

TA的得分主题

发表于 2014-1-8 16:12 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-21 16:37 , Processed in 0.038039 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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