|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我也只会比较笨的方法,共同学习吧
- Sub 生成报表()
- Dim i As Integer
- Dim j As Integer
- Dim n As Integer
- Dim arr
- Dim x As Integer
- Dim m As Integer
- Application.ScreenUpdating = False
- Worksheets("原始表").Activate
- x = Worksheets("原始表").[a65536].End(xlUp).Row
- m = (x + 2) / 4
- ReDim arr(1 To m, 1 To 23)
- n = 0
- For i = 2 To x Step 4
- n = n + 1
- arr(n, 1) = n
- For j = 2 To 5
- arr(n, j) = Cells(i, j - 1)
- Next j
- arr(n, 6) = Cells(i + 1, 3)
- arr(n, 7) = Cells(i, 5)
- arr(n, 8) = Cells(i, 6)
- arr(n, 9) = Cells(i, 10)
- arr(n, 10) = Cells(i + 1, 10)
- arr(n, 11) = Cells(i + 2, 10)
- arr(n, 12) = Cells(i + 3, 10)
- arr(n, 13) = Cells(i, 11)
- arr(n, 14) = Cells(i + 1, 11)
- arr(n, 15) = Cells(i + 2, 11)
- arr(n, 16) = Cells(i + 3, 11)
- arr(n, 17) = Cells(i, 13)
- arr(n, 18) = Cells(i, 12)
- arr(n, 19) = Cells(i + 1, 6)
- arr(n, 22) = Cells(i + 1, 5)
- arr(n, 23) = Cells(i, 14)
- Next i
- Worksheets("报表").Range("a2:aa5000").ClearContents
- Worksheets("报表").Range("a2").Resize(m, 23) = arr
- Worksheets("报表").Activate
- Range("T2").Select
- ActiveCell.FormulaR1C1 = _
- "=IF(R[1]C4=0,MAX(RC9:R[1]C12)-MIN(RC9:R[1]C12),MAX(RC9:RC12)-MIN(RC9:RC12))"
- Range("u2").Select
- ActiveCell.Formula = "=if(b2 = """","""",month(b2))"
- Range("T2:U" & m + 1).Select
-
- Selection.FillDown
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|