若E2輸入日期
D12=SHEETS("年齡")中,E2日期以前(含E2的日期)回籠的總和,
例如E2=2010/8/15,則D12=SHEETS("年齡")中,R3:Y7總和
有人指導如下
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$E$2" Then Exit Sub
Dim i As Integer, k As Byte, Col
With Sheets("年齡")
For i = 3 To .[a65536].End(3).Row
If .Cells(i, "A") <= [e2] Then
For k = 18 To 25
Col = Col + .Cells(i, k)
Next
End If
Next
[d12] = Col
End With
End Sub[attach]2781[/attach]
我若改成下面的式子為何不可以?
Private Sub Ex()
Dim i As Integer, k As Byte, Col
With Sheets("年齡")
For i = 3 To .[a65536].End(3).Row
If .Cells(i, "A") <= [e2] Then
For k = 18 To 25
Col = Col + .Cells(i, k)
Next
End If
Next
[d12] = Col
End With
End Sub