andrianocaras
New Member
- Joined
- Jan 25, 2016
- Messages
- 4
i need a help with my VBA excel . . . i have an excel like the picture above and i was trying countifs with condition between 2 date
in counting i got the right answer 5 but in counting1 i got 8 instead the right answer 5 in counting2 i got 0 instead the right answer 5 or wrong answer 8 just like in counting1, in counting2 i just reverse the condition this is the code
HTML:
Dim rB As Range
MyDate = CDate(Range("B6"))
MyDate1 = CDate(Range("B2"))
Set rB = Range("B2", Range("B" & Rows.Count).End(xlUp))
LS = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
counting = Application.WorksheetFunction.CountIfs(rB, ">=" & MyDate1, rB, "<=" & MyDate)
counting1 = Application.WorksheetFunction.CountIfs(rB.Offset(0, 1), "<=" & MyDate, rB, ">=" & MyDate1)
counting2 = Application.WorksheetFunction.CountIfs(rB.Offset(0, 1), ">=" & MyDate1, rB, "<=" & MyDate)
MsgBox counting
MsgBox counting1
MsgBox counting2
counting = i want to count B with condition >=Mydate1 and <=MyDate i got answer 5
counting1 = i want to count C with condition <=Mydate and >=MyDate1 i got answer 8
counting2 = i want to count C with condition >=Mydate1 and <=MyDate i just reverse the condition, i got answer 0
can anyone help me so i can get the right answer ??