Hi
I'm trying to use vba to go through list of items and get a sum of receipts/commitment for each item. It worked fine till I added date condition st_date and end_date. date_rng consist dates in format dd/mm/yyyy eg. 08/05/2017
first sumifs works OK, but second one fails.
Appreciate help or suggestions.
when vba puts st_date and end_date to worksheet results have 2 different formats, thought both are date type
[TABLE="width: 170"]
<tbody>[TR]
[TD]cells(2,10)[/TD]
[TD="align: right"]01-May[/TD]
[/TR]
[TR]
[TD]cells(3,10) [/TD]
[TD="align: right"]15/05/2017[/TD]
[/TR]
</tbody><colgroup><col span="2"></colgroup>[/TABLE]
THANKS
I'm trying to use vba to go through list of items and get a sum of receipts/commitment for each item. It worked fine till I added date condition st_date and end_date. date_rng consist dates in format dd/mm/yyyy eg. 08/05/2017
first sumifs works OK, but second one fails.
Appreciate help or suggestions.
Code:
str_date = Application.InputBox(prompt:="Please enter focus week - dd/mm/yyyy", Type:=2)
st_date = Format(CDate(str_date), "dd-mmm")
end_date = DateAdd("d", 14, st_date)
Cells(2, 10) = st_date
Cells(3, 10) = end_date
x = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To x
sku = Cells(i, 1)
mp = Cells(i, 5)
dd = WorksheetFunction.SumIfs([comm_rng], [sku_rng], sku, [plant_rng], mp, [doc_rng], ">7", [date_rng], ">=" & st_date)
comm = WorksheetFunction.SumIfs([rece_rng], [sku_rng], sku, [plant_rng], mp, [doc_rng], "<3", [date_rng], "<=" & end_date)
Cells(i, 6) = dd
Cells(i, 7) = comm
Next
when vba puts st_date and end_date to worksheet results have 2 different formats, thought both are date type
[TABLE="width: 170"]
<tbody>[TR]
[TD]cells(2,10)[/TD]
[TD="align: right"]01-May[/TD]
[/TR]
[TR]
[TD]cells(3,10) [/TD]
[TD="align: right"]15/05/2017[/TD]
[/TR]
</tbody><colgroup><col span="2"></colgroup>[/TABLE]
THANKS
Last edited: