|
本帖最后由 考试加油站 于 2012-3-23 10:26 编辑
表中有3个文件夹,要求:
1.新生成的表放在《生成的本月数据》中。
2.新生成的表中本月数据等于<去年同期数>中文件的去年本月数的1.32倍。(实际也就是说比去年增长32%)
3.新生成表的本月累计数等于本新表的本月数+<原始数据上月>表的本月累计。(实际上就是说本月累计=本月数+上月累计数)
说了这么多:其实原理很简单。领导要求本月新表数据要比去年同期增长32%,本月累计数=本月数+前一个月的累计数。
原代码如下:
产值产量表中数据doitbest 设计.rar
(19.6 KB, 下载次数: 4)
- Public Sub qw()
- Dim S, D, mydir$, sht As Worksheet, ar, i%, a%, b%, n%
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Show
- CreateObject("Scripting.FileSystemObject").CopyFolder .SelectedItems(1), ThisWorkbook.Path & "\生成的本月数据"
- End With
- 'Stop
- mydir = Dir(ThisWorkbook.Path & "\生成的本月数据" & "\*.xls")
- n = 1
- Do While Len(mydir) > 0
- Workbooks.Open ThisWorkbook.Path & "\生成的本月数据" & mydir
- Debug.Print mydir
- For Each sht In ActiveWorkbook.Worksheets
- With sht
- If .[a5] = "" Then Exit For
- ar = .Range("d5:g" & .[a65536].End(3).Row)
- For i = 1 To UBound(ar)
- a = ar(i, 1)
- ' Debug.Print sht.Index = 1 And i = UBound(ar)
- ar(i, 1) = IIf(sht.Index = 1 And i = UBound(ar), Round(ar(i, 1) * 1.1, 1), Round(ar(i, 1) * 1.1, 0))
- ar(i, 2) = IIf(sht.Index = 1 And i = UBound(ar), Round(ar(i, 2) + ar(i, 1), 1), Round(ar(i, 2) + ar(i, 1), 0))
- a = ar(i, 3)
- ar(i, 3) = IIf(sht.Index = 1 And i = UBound(ar), Round(ar(i, 3) * 1.1, 1), Round(ar(i, 3) * 1.1, 0))
- ar(i, 4) = IIf(sht.Index = 1 And i = UBound(ar), Round(ar(i, 4) + ar(i, 3), 1), Round(ar(i, 4) + ar(i, 3), 0))
- Next
- .Cells(5, 4).Resize(UBound(ar), 4).NumberFormatLocal = "G/通用格式"
- .Cells(5, 4).Resize(UBound(ar), 4) = ar
- End With
- Next
- ActiveWorkbook.Close (True)
- mydir = Dir
- n = n + 1
- If n > CreateObject("Scripting.FileSystemObject").GetFolder(ThisWorkbook.Path & "\生成的本月数据").Files.Count Then Exit Do
- Loop
- End Sub
复制代码
|
|