|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iRow, iCol, iRow_dn As Integer
Dim rng1, rng2, rng, cel As Range
iRow = Target.Row
iCol = Target.Column
iRow_dn = [A65536].End(xlUp).Row
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
If iRow >= 3 And iCol = 2 And Cells(iRow, iCol) <> "" Then
Cells(iRow, 1) = Date '在第一列填写日期
ElseIf iRow >= 3 And iCol = 2 And Cells(iRow, iCol) = "" Then
Range(Cells(iRow, 1), Cells(iRow, 5)).ClearContents
ElseIf iRow >= 3 And (iCol = 3 Or iCol = 4) And iRow = iRow_dn Then
Total1 = Application.WorksheetFunction.Sum(Range("C3:C" & iRow))
Total2 = Application.WorksheetFunction.Sum(Range("D3:D" & iRow))
Cells(iRow, 5) = Total1 - Total2 '在第五列运算
ElseIf iRow >= 3 And (iCol = 3 Or iCol = 4) And iRow <> iRow_dn Then
Set rng = Range("E" & iRow & ":E" & iRow_dn)
For Each cel In rng
Set rng1 = Range("C3:C" & cel.Row)
Set rng2 = Range("D3:D" & cel.Row)
Total1 = Application.WorksheetFunction.Sum(rng1)
Total2 = Application.WorksheetFunction.Sum(rng2)
cel.Value = Total1 - Total2
Next cel
End If
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Activate()
ActiveSheet.[B65536].End(xlUp).Offset(1, 0).Select '打开现金账后自动定位到需要输入数据的第一个单元格。
End Sub
请高手帮忙解释一下代码的意思!我想借用里边的一部分功能!
|
|