|
H组 hactnet
来交下作业,请老师看看
Private Sub CommandButton1_Click()
'小计例1
Dim x As Integer, k1 As Integer, k2 As Integer
k1 = 2
For x = 2 To 30
If DateDiff("m", Range("a" & x), Range("a" & x + 1)) Then
k2 = x
Rows(x + 1).Insert
Range("a" & x + 1) = "小计"
Range("a" & x + 1).Offset(0, 2) = "=sum(c" & k1 & ":c" & k2 & ")"
Range("a" & x + 1).Offset(0, 2).Resize(1, 2).FillRight
x = x + 1
k1 = k2 + 2
End If
Next x
End Sub
Sub 小计例2()
Dim x As Integer, k1 As Integer, k2 As Integer
k1 = 2
For x = 2 To 30
'For x = 2 To Range("A65536").End(xlUp).Row + 10
'If Range("a" & x) = "" Then Exit Sub
If DateDiff("m", Range("a" & x), Range("a" & x + 1)) Then
'**************************************************************
'If Month(Cells(x, 1)) <> Month(Cells(x + 1, 1)) Then
'If Year(Cells(x, 1)) = Year(Cells(x + 1, 1)) And Month(Cells(x, 1)) <> Month(Cells(x + 1, 1)) Then
'
'**************************************************************
k2 = x
Rows(x + 1).Insert
Range("a" & x + 1) = "小计"
Range("a" & x + 1).Offset(0, 2) = Application.Sum(Range(Range("c" & k1), Range("c" & x))) '"=sum(c2:c5)"
Range("a" & x + 1).Offset(0, 3) = Application.Sum(Range(Range("d" & k1), Range("d" & x))) '"=sum(d2:d5)"
x = x + 1
k1 = k2 + 2
'**************************************************************
'Else
'Rows(x + 2).Insert
' Range("a" & x + 1) = "小计"
' Range("a" & x + 1).Offset(0, 2) = Application.Sum(Range(Range("c" & k), Range("c" & x))) '"=sum(c2:c5)"
' x = x + 1
' k = x + 1
'*************************************************************
End If
Next x
End Sub
Private Sub CommandButton2_Click()
Range("c:c").SpecialCells(xlCellTypeBlanks).Offset(0, 2) = "1"
End Sub
Private Sub CommandButton3_Click()
'恢复表格
Range("c:c").SpecialCells(xlCellTypeBlanks).Offset(0, 2) = ""
Range("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub |
评分
-
查看全部评分
|