maghari
08-08-2020, 03:21 AM
hello
i try sum data based on cell value contains date so whan i write the date in g2 it supposes sum from the first date to what i write in g2 and copy theses data from a2:e to sheet2 this my code doesn't work also not give me error
Dim l As LongDim LastRow As Long
Dim oWkSht As Worksheet
Dim FirstDate As Date
Dim LastDate As Date
'Dim tsales As Long '<-- not used in this code
Set oWkSht = Worksheets("sheet2")
FirstDate = DateSerial(Year(Date), Month(Date), 1)
LastDate = DateSerial(Year(Date), Month(Date) + 1, 0)
LastRow = oWkSht.Range("A100000").End(xlUp).Row
Sheets("sheet1").Range("g2").Value = Application.WorksheetFunction.SumIfs(oWkSht.Range("e2:e" & LastRow), oWkSht.Range("a2:a" & LastRow), ">=" & CLng(FirstDate), oWkSht.Range("a2:a" & LastRow), "<=" & CLng(LastDate))
End sub
i try sum data based on cell value contains date so whan i write the date in g2 it supposes sum from the first date to what i write in g2 and copy theses data from a2:e to sheet2 this my code doesn't work also not give me error
Dim l As LongDim LastRow As Long
Dim oWkSht As Worksheet
Dim FirstDate As Date
Dim LastDate As Date
'Dim tsales As Long '<-- not used in this code
Set oWkSht = Worksheets("sheet2")
FirstDate = DateSerial(Year(Date), Month(Date), 1)
LastDate = DateSerial(Year(Date), Month(Date) + 1, 0)
LastRow = oWkSht.Range("A100000").End(xlUp).Row
Sheets("sheet1").Range("g2").Value = Application.WorksheetFunction.SumIfs(oWkSht.Range("e2:e" & LastRow), oWkSht.Range("a2:a" & LastRow), ">=" & CLng(FirstDate), oWkSht.Range("a2:a" & LastRow), "<=" & CLng(LastDate))
End sub