Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!

[通知] 统计VBA学习小组正式组的积分帖之作业上交贴(第14周)

  [复制链接]
发表于 2012-4-5 21:01 | 显示全部楼层
Private Sub CommandButton1_Click()
Dim i, k As Integer
k = 2
For i = 3 To 50
If Month(Range("a" & i)) <> Month(Range("A" & i - 1)) Then
Rows(i).Insert
Range("a" & i) = "小计"
Range("c" & i) = "=sum(c" & k & ":c" & i - 1 & ")"
Range("d" & i) = "=sum(d" & k & ":d" & i - 1 & ")"
i = i + 1
k = i
End If
Next i
End Sub

Private Sub CommandButton2_Click()
Range("a2", Range("a65536").End(xlUp)).Offset(0, 3).SpecialCells(xlCellTypeBlanks).Offset(0, 1) = 1
End Sub
Private Sub CommandButton3_Click()
Columns("b:b").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Range("e2:" & Range("e65536").End(xlUp).Address).ClearContents
End Sub

评分

参与人数 1金币 +8 收起 理由
兰色幻想 + 8 答案正确

查看全部评分

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

发表于 2012-4-5 21:26 | 显示全部楼层
  1. Private Sub CommandButton1_Click()
  2. Dim i, r, V As Integer
  3.    
  4.     i = [a65536].End(xlUp).Row
  5.     r = 2
  6.     V = r
  7. Do
  8.     r = r + 1
  9.     If Month(Cells(r, 1)) > Month(Cells(r - 1, 1)) Then
  10.         Rows(r).Insert
  11.         Cells(r, 1) = "小计"
  12.         Cells(r, 3).Formula = "=SUM(C" & V & ":C" & r - 1 & ")"
  13.         Cells(r, 4).Formula = "=SUM(D" & V & ":D" & r - 1 & ")"
  14.         V = r + 1
  15.         r = r + 2
  16.     End If
  17. Loop Until Cells(r, 1) = 0

  18. Range("a1").CurrentRegion.Value = Range("a1").CurrentRegion.Value
  19. End Sub

  20. Private Sub CommandButton2_Click()
  21. Dim r As Integer
  22.     r = [a65536].End(xlUp).Row

  23.     With Range("D2:D" & r)
  24.     .Replace "0", ""
  25.     .Copy
  26.     End With
  27.     Range("e2").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
  28.     Selection.Replace "0", "1"
  29. End Sub
  30. Private Sub CommandButton3_Click()
  31. Dim d, arr
  32. Dim r As Integer

  33. If Application.CountIf(Range("A:A"), "小计") Then
  34. arr = Range("a1").CurrentRegion

  35. Set d = CreateObject("Scripting.Dictionary")

  36. For r = 1 To UBound(arr)
  37.     If arr(r, 1) = "小计" Then
  38.         d(arr(r, 1) & r) = r & ":" & r
  39.     End If
  40. Next

  41. Range(Join(d.items, ",")).Delete
  42. Range("e2:e" & UBound(arr)).ClearContents
  43. End If

  44. End Sub

复制代码
这几天工作太忙,一直没时间上传作业,希望老师能批阅一下?

11课.rar

858.79 KB, 下载次数: 6

点评

答案太复杂了  发表于 2012-4-17 17:32

评分

参与人数 1金币 +3 收起 理由
兰色幻想 + 3

查看全部评分

回复

使用道具 举报

发表于 2012-4-5 23:26 | 显示全部楼层
zhouyunj 发表于 2012-3-29 11:25
注明自己的新组编号:旧组是13组。申请过2群,未收到回复通过通知
论坛ID:zhouyunj


最新分组更新:C20:zhouyunj
回复

使用道具 举报

发表于 2012-4-9 14:10 | 显示全部楼层
g17:szczm121
Dim c As Integer, z As Integer, m As Integer, m1 As Integer
Sub 插入小计行()
    z = Range("A65536").End(xlUp).Row
    For c = 2 To z
        If Range("a" & c) <> "" Then
            If Month(Range("a" & c + 1)) <> Month(Range("a" & c)) Then
                Rows(c + 1).Insert
            End If
        End If
    Next c
    z = Range("A65536").End(xlUp).Row + 1
    Range("A2:A" & z).SpecialCells(xlCellTypeBlanks) = "小计"
    m1 = 2
    For m = 2 To z
        If Range("a" & m) = "小计" Then
            Range("b" & m).Offset(0, 1) = Application.Sum(Range("c" & m1 & ":c" & m - 1))
            Range("b" & m).Offset(0, 2) = Application.Sum(Range("d" & m1 & ":d" & m - 1))
            m1 = m + 1
        End If
    Next m
End Sub
Sub 填写标识()
z = Range("c65536").End(xlUp).Row
Range("c2:c" & z).SpecialCells(xlCellTypeBlanks).Offset(0, 2) = 1
End Sub
Sub 删除小计行()
Range("e:e").ClearContents
Columns(2).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
第11课作业题(szczm121).rar (16.36 KB, 下载次数: 3)

评分

参与人数 1金币 +7 收起 理由
兰色幻想 + 7 答案正确

查看全部评分

回复

使用道具 举报

发表于 2012-4-9 23:50 | 显示全部楼层
本帖最后由 ls 于 2012-4-9 23:52 编辑

游客,如果您要查看本帖隐藏内容请回复


Option Explicit

Private Sub CommandButton1_Click()
    Dim i As Integer, j As Integer
    For i = Range("a65536").End(xlUp).Row To 2 Step -1
        If Month(Range("a" & i)) <> Month(Range("a" & i + 1)) Then
            Range("a" & i + 1).EntireRow.Insert
            Range("a" & i + 1) = "小计"
        End If
    Next i
    j = 2
    For i = 2 To Range("a65536").End(xlUp).Row
        If Range("A" & i) = "小计" Then
            Range("c" & i) = Application.Sum(Range(Range("c" & j), Range("c" & i - 1)))
            Range("d" & i) = Application.Sum(Range(Range("c" & j), Range("c" & i - 1)))
            j = i + 1
        End If
    Next i
End Sub

Private Sub CommandButton2_Click()
    Range("c2:c" & [c65536].End(3).Row).SpecialCells(xlCellTypeBlanks).Offset(, 2) = 1
End Sub
Private Sub CommandButton3_Click()
    Columns("B:B").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.Delete
    Range("e2:e" & [e65536].End(3).Row).ClearContents
End Sub



评分

参与人数 1金币 +8 收起 理由
兰色幻想 + 8 答案正确

查看全部评分

回复

使用道具 举报

发表于 2012-4-20 23:29 | 显示全部楼层
作业重做
  1. Private Sub CommandButton1_Click()
  2.     Dim 入库合计, 发出合计, x
  3.     For x = 2 To Range("a65536").End(xlUp).Row + 12
  4.         If Cells(x, 1) = "" Then Exit Sub
  5.             入库合计 = 入库合计 + Cells(x, 4)
  6.             发出合计 = 发出合计 + Cells(x, 3)
  7.         If Month(Cells(x, 1)) <> Month(Cells(x + 1, 1)) Then
  8.             Rows(x + 1).Insert
  9.             x = x + 1
  10.               Cells(x, 1) = "小计"
  11.               Cells(x, 3) = 发出合计
  12.               Cells(x, 4) = 入库合计
  13.               发出合计 = 0
  14.               入库合计 = 0
  15.         End If
  16.     Next x
  17. End Sub
  18. Private Sub CommandButton2_Click()
  19.     Range("c2:C" & Range("a65536").End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Offset(0, 2) = 1
  20. End Sub
  21. Private Sub CommandButton3_Click()
  22.     Range("b2:b" & Range("a65536").End(xlUp).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  23.     Range("e2:e" & Range("a65536").End(xlUp).Row) = ""
  24. End Sub
复制代码
回复

使用道具 举报

发表于 2015-6-18 08:01 | 显示全部楼层
5626663
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-24 19:26 , Processed in 0.415735 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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