PC Review


Reply
Thread Tools Rate Thread

Coding a SumProduct formula

 
 
Otto Moehrbach
Guest
Posts: n/a
 
      28th Oct 2006
Excel XP, WinXP
I have a number of columns of dates.
I want to get the number of instances (cells) of dates that match specific
months and years, in a specific column.
The sheet formula:
=SUMPRODUCT((MONTH(A1:A100)=1)*(YEAR(A1:A100)=2001))
works just fine, but I want to use VBA so the user can input the month,
year, and column.
My code looks like this:
TheCol = Application.InputBox...........
TheMonth = Application.InputBox..............
TheYear = Application.InputBox...............
Set TheRng = Range(Cells(2, TheCol), Cells(Rows.Count, TheCol).End(xlUp))
MsgBox Application.SumProduct((Application.Month(TheRng) = 1) *
(Application.Year(TheRng) = TheYear))

I get the error "Object doesn't support this property or method." on the
last line (MsgBox).
What am I doing wrong? Is it that SumProduct is one of the sheet formulas
that cannot be used in VBA?
Thanks for your time. Otto


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sk1C?=
Guest
Posts: n/a
 
      28th Oct 2006
MsgBox Evaluate("=SUMPRODUCT((MONTH(" & TheRng.Address & ")=" & TheMonth &
")*(YEAR(" & TheRng.Address & ")=" & TheYear & "))")

"Otto Moehrbach" wrote:

> Excel XP, WinXP
> I have a number of columns of dates.
> I want to get the number of instances (cells) of dates that match specific
> months and years, in a specific column.
> The sheet formula:
> =SUMPRODUCT((MONTH(A1:A100)=1)*(YEAR(A1:A100)=2001))
> works just fine, but I want to use VBA so the user can input the month,
> year, and column.
> My code looks like this:
> TheCol = Application.InputBox...........
> TheMonth = Application.InputBox..............
> TheYear = Application.InputBox...............
> Set TheRng = Range(Cells(2, TheCol), Cells(Rows.Count, TheCol).End(xlUp))
> MsgBox Application.SumProduct((Application.Month(TheRng) = 1) *
> (Application.Year(TheRng) = TheYear))
>
> I get the error "Object doesn't support this property or method." on the
> last line (MsgBox).
> What am I doing wrong? Is it that SumProduct is one of the sheet formulas
> that cannot be used in VBA?
> Thanks for your time. Otto
>
>
>

 
Reply With Quote
 
Otto Moehrbach
Guest
Posts: n/a
 
      28th Oct 2006
JMB
Thanks for that. I'll try it. Otto
"JMB" <(E-Mail Removed)> wrote in message
news:CD688910-F8BF-4C1B-A2E5-(E-Mail Removed)...
> MsgBox Evaluate("=SUMPRODUCT((MONTH(" & TheRng.Address & ")=" & TheMonth &
> ")*(YEAR(" & TheRng.Address & ")=" & TheYear & "))")
>
> "Otto Moehrbach" wrote:
>
>> Excel XP, WinXP
>> I have a number of columns of dates.
>> I want to get the number of instances (cells) of dates that match
>> specific
>> months and years, in a specific column.
>> The sheet formula:
>> =SUMPRODUCT((MONTH(A1:A100)=1)*(YEAR(A1:A100)=2001))
>> works just fine, but I want to use VBA so the user can input the month,
>> year, and column.
>> My code looks like this:
>> TheCol = Application.InputBox...........
>> TheMonth = Application.InputBox..............
>> TheYear = Application.InputBox...............
>> Set TheRng = Range(Cells(2, TheCol), Cells(Rows.Count, TheCol).End(xlUp))
>> MsgBox Application.SumProduct((Application.Month(TheRng) = 1) *
>> (Application.Year(TheRng) = TheYear))
>>
>> I get the error "Object doesn't support this property or method." on the
>> last line (MsgBox).
>> What am I doing wrong? Is it that SumProduct is one of the sheet
>> formulas
>> that cannot be used in VBA?
>> Thanks for your time. Otto
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with formula in vb coding mc Microsoft Excel Programming 5 7th Jul 2009 01:17 PM
Nesting a sumproduct formula within a sumif formula. =?Utf-8?B?amVycnltY20=?= Microsoft Excel Misc 2 3rd Oct 2007 03:35 PM
Coding Formula =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Programming 2 21st Sep 2007 01:36 PM
Help with Coding a Formula Please Paul Black Microsoft Excel Programming 7 18th Aug 2005 07:12 PM
Formula Color Coding =?Utf-8?B?QW5kcmV3?= Microsoft Excel Misc 5 25th Mar 2005 08:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:36 AM.