![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Feb 2004
Posts: 198
|
This a continuation of my post in
http://www.mrexcel.com/board2/viewtopic.php?t=83204 but because the question is unrelated to For Each, I think it is more appropriately in another topic. My goal is to do a sumproduct within a sub. The following formula works correctly. =SUMPRODUCT(($C$2:$C$9=H3)*($D$2:$D$9=I3)*($A$2:$A$9<=G3)*($B$2:$B$9>=G3)*($E$2:$E$9)) However, the problem gets more complicated when the lookups reside in another document. I felt it would be more appropriate to automate the task in a sub. What follows is where I am so far: Dim cctr As Integer mytimer = Timer master = "E:\Sales Accounting\D F I\DFI Master File.xls" 'Workbooks.Open Filename:=(master) 'ActiveWindow.ActivateNext lastrow = Range("A65536").End(xlUp).Row cctr = InputBox("What Cost Center should be updated?") Set BEGrange = Workbooks("DFI Master File.xls").Worksheets("Price Lists").Range("a2:a9000") Set ENDrange = Workbooks("DFI Master File.xls").Worksheets("Price Lists").Range("b2:b9000") Set PLrange = Workbooks("DFI Master File.xls").Worksheets("Price Lists").Range("c2:c9000") Set ITrange = Workbooks("DFI Master File.xls").Worksheets("Price Lists").Range("d2:d9000") Set DPrange = Workbooks("DFI Master File.xls").Worksheets("Price Lists").Range("e2:e9000") For i = 2 To lastrow If Range("v" & i).Value = cctr Then Range("H" & i).Value = Application.WorksheetFunction.SumProduct((PLrange = Range("p" & i).String) * (ITrange = Range("f" & i).String) * (BEGrange <= Range("e" & i).Value) * (ENDrange >= Range("e" & i).Value) * (DPrange)) Next i I am defining the lookup paths for each portion of the array to simplify the application code. The error I am receiving is a runtime error. Object doesn't support this product or method. I interpret this error to mean there is a problem with the equation syntax, but for the life of me, I cannot figure out what it is. Thank you for taking the time to read this far! -Jarrod |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|