Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default count using multiple criteria


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default count using multiple criteria

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default count using multiple criteria


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default count using multiple criteria

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default count using multiple criteria


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default count using multiple criteria

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count with multiple criteria in multiple cells Mike H Excel Worksheet Functions 1 February 9th 10 04:02 PM
Filter Multiple Columns on Multiple Criteria and count the last co LBitler Excel Worksheet Functions 2 February 12th 09 08:36 PM
To count the data using multiple criteria in multiple columns Rajesh New Users to Excel 5 December 15th 08 04:07 PM
Count multiple cells against multiple criteria in an Excel spreads EricB Excel Worksheet Functions 7 June 3rd 08 09:09 PM
Multiple Criteria, Count If, Sum Product to get count across range Jonathan Excel Worksheet Functions 5 January 9th 08 11:32 PM


All times are GMT +1. The time now is 05:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"