Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Coding a SumProduct formula
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Coding a SumProduct formula
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Coding a SumProduct formula
JMB
Thanks for that. I'll try it. Otto "JMB" wrote in message ... 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
converting question; function, formula, or coding? | Excel Worksheet Functions | |||
Implant macro coding into ASP coding | Excel Programming | |||
Help with Coding a Formula Please | Excel Programming | |||
Formula Color Coding | Excel Discussion (Misc queries) | |||
vba coding for formula in cell | Excel Programming |