0

I've got a script that generates reports from a data set. The data set relates to a customer support log of tickets/tracking numbers, with basic ticket info such as when the ticket was opened, who the ticket was assigned to and what the main issue/workload was. My goal is to create a report that already exists but is completed manually with pivot tables (that almost nobody knows how to use) and avoids using formulas.

The basic report is how many of each workload was completed by each employee per month. Easily doable with a pivot table, except most people don't know how. This excel formula gets what I want for January, =SUMPRODUCT((data!Column1="Employee1")*(data!Column2="Workload A")*(data!Column3>=DATEVALUE("2019-1"))*(data!Column3<DATEVALUE("2019-2"))). The drawback of the data is that the dates are date values that are formatted as short dates. The solution I have in VBA:

Cell.Value = "=SUMPRODUCT((data!" & AssigneeCol.Address & "=""" & Assignee.Value & """)*(data!" & WorkloadCol.Address & "=""" & Workload.Value & """)*(data!" & DateCol.Address & ">=DATEVALUE(""" & Worksheet.Name & """))*(data!" & DateCol.Address & "<DATEVALUE(""" & Year & Month2 & """)))"

This leaves a gigantic formula in excel which is referenced to the data worksheet which will not be included in the report (though I suppose it could be hidden). I'd prefer to use values to make the sheet easier to handle by management. I tried using Evaluate, but it makes the cell value #VALUE!

CheckCell.Value = Evaluate("=SUMPRODUCT((data!" & AssigneeCol.Address & "=""" & Assignee.Value & """)*(data!" & WorkloadCol.Address & "=""" & Workload.Value & """)*(data!" & DateCol.Address & ">=DATEVALUE(""" & Worksheet.Name & """))*(data!" & DateCol.Address & "<DATEVALUE(""" & Year & Month2 & """)))")

Is this because of an inherent limitation with Evaluate(), ie: DATEVALUE within SUMPRODUCT? As far as I can tell it should work, but I have no idea.

4

1 回答 1

2

没有解决您关于评估的问题,但您仍然可以使用单元格内公式,然后用结果替换公式

With Cell
   .Formula = "=SUMPRODUCT((data!...  etc etc"
   DoEvents
   .Value = .Value
End With
于 2019-03-20T16:57:22.527 回答