这已经过测试。它将与一个长度不断变化的表格一起工作,并且可以将这个概念适应于许多需求。玩的开心。
Sub ScrapCount()
Dim str_dateMin As String
Dim str_dateMax As String
Dim dateMin As Date
Dim dateMax As Date
Dim lastRow As Long
Dim subTotal As Double
Dim lookupDate As Date
Dim lRow As Long
lastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
subTotal = 0
str_dateMin = InputBox("Input beginning date, mm/dd/yyyy:")
str_dateMax = InputBox("Input end date, mm/dd/yyyy:")
dateMin = CDate(str_dateMin)
dateMax = CDate(str_dateMax)
For lRow = 2 To lastRow
lookupDate = Sheets("Sheet1").Cells(lRow, "C").Value
If dateMin <= lookupDate And lookupDate <= dateMax Then
subTotal = subTotal + Sheets("Sheet1").Cells(lRow, "E").Value
End If
Next lRow
MsgBox ("Total scrap for date range = " & subTotal)
End Sub
其中宏创建?请发布。 – ZAT 2014-12-02 17:33:11