Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Column A has texts Column B has dates Want to count rows having text='Apples' for dates between today and 14 days back. In other words read it as "counting number of Apple sale transactions for a fortnight. I want to write a user defined VBA function that can be called in excel sheet cells. I tried countif but it takes only one criteria. Tried 'count' and 'if' together and also 'sum' but could not succeed much. How we can achieve above mentioned counting. Thanks. -- nougain ------------------------------------------------------------------------ nougain's Profile: http://www.excelforum.com/member.php...o&userid=32031 View this thread: http://www.excelforum.com/showthread...hreadid=528499 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
No need for VBA
=SUMPRODUCT(--(A1:A100="Apples"),--(B1:B100=TODAY()-14),-(B1:B100<=TODAY()) ) -- HTH Bob Phillips (remove nothere from email address if mailing direct) "nougain" wrote in message ... Column A has texts Column B has dates Want to count rows having text='Apples' for dates between today and 14 days back. In other words read it as "counting number of Apple sale transactions for a fortnight. I want to write a user defined VBA function that can be called in excel sheet cells. I tried countif but it takes only one criteria. Tried 'count' and 'if' together and also 'sum' but could not succeed much. How we can achieve above mentioned counting. Thanks. -- nougain ------------------------------------------------------------------------ nougain's Profile: http://www.excelforum.com/member.php...o&userid=32031 View this thread: http://www.excelforum.com/showthread...hreadid=528499 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Thanks. For simplicity I tried to wrap it in a VBA function but it is failing at Application.SumProduct row: Function qae(weeklyFridayDate As Date) As Integer Dim dateRange As range Dim dataRange As range Dim countData As Integer Set dataRange = Sheets("DT").range("D11:D1000") Set dateRange = Sheets("DT").range("E11:E1000") qae = Application.SumProduct(--(dataRange = "Internal") * --(dateRange (weeklyFridayDate - 12)) * --(dateRange <= (weeklyFridayDate + 2))) End Function -- nougain ------------------------------------------------------------------------ nougain's Profile: http://www.excelforum.com/member.php...o&userid=32031 View this thread: http://www.excelforum.com/showthread...hreadid=528499 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try
qae = Activesheet.Evaluate("=SumProduct(--(DT!D11:D1000= ""Internal"") ," & _ "--(DT!E11:E1000(" & weeklyFridayDate & "-12))," & _ "--(DT!E11:E1000<=(" & weeklyFridayDate & "+2)))") -- HTH Bob Phillips (remove nothere from email address if mailing direct) "nougain" wrote in message ... Thanks. For simplicity I tried to wrap it in a VBA function but it is failing at Application.SumProduct row: Function qae(weeklyFridayDate As Date) As Integer Dim dateRange As range Dim dataRange As range Dim countData As Integer Set dataRange = Sheets("DT").range("D11:D1000") Set dateRange = Sheets("DT").range("E11:E1000") qae = Application.SumProduct(--(dataRange = "Internal") * --(dateRange (weeklyFridayDate - 12)) * --(dateRange <= (weeklyFridayDate + 2))) End Function -- nougain ------------------------------------------------------------------------ nougain's Profile: http://www.excelforum.com/member.php...o&userid=32031 View this thread: http://www.excelforum.com/showthread...hreadid=528499 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I tried it but couldn't succeed. To get your suggested code compiled removed two _ (underscores), not sure if that is correct. Once compile it gave me 0 as result for all inputs which is not correct as withou VBA I get correct result. I am not experienced in VBA so couldn't debug it much to see what wa going on. Any further help is highly appreciated. Thanks -- nougai ----------------------------------------------------------------------- nougain's Profile: http://www.excelforum.com/member.php...fo&userid=3203 View this thread: http://www.excelforum.com/showthread.php?threadid=52849 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
NG wrap-around did us no favours here.
Try Dim sFormula As String sFormula = "=SumProduct(--(DT!D11:D1000= ""Internal"") ," & _ "--(DT!E11:E1000(" & weeklyFridayDate & "-12))," & _ "--(DT!E11:E1000<=(" & weeklyFridayDate & "+2)))" qae = ActiveSheet.Evaluate(sFormula) If that fals, try mailing the workbook to me perhaps? -- HTH Bob Phillips (remove nothere from email address if mailing direct) "nougain" wrote in message ... I tried it but couldn't succeed. To get your suggested code compiled I removed two _ (underscores), not sure if that is correct. Once compiled it gave me 0 as result for all inputs which is not correct as without VBA I get correct result. I am not experienced in VBA so couldn't debug it much to see what was going on. Any further help is highly appreciated. Thanks. -- nougain ------------------------------------------------------------------------ nougain's Profile: http://www.excelforum.com/member.php...o&userid=32031 View this thread: http://www.excelforum.com/showthread...hreadid=528499 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Count with multiple criteria in multiple cells | Excel Worksheet Functions | |||
Filter Multiple Columns on Multiple Criteria and count the last co | Excel Worksheet Functions | |||
To count the data using multiple criteria in multiple columns | New Users to Excel | |||
Count multiple cells against multiple criteria in an Excel spreads | Excel Worksheet Functions | |||
Multiple Criteria, Count If, Sum Product to get count across range | Excel Worksheet Functions |