我需要帮助,
我有两张表格:一张有一个月(一月、二月等)一个月内一个月内一个雇员在项目/建议书上工作的天数,另一个有雇员工资。我需要多个匹配率和一月日,其中所有的标准是相同的,在两个表中,然后显示和如果类型:“项目”和年份“2018年”。我需要为每个月分别做这个和,但是如果我找到了如何做一个,那么rest应该是简单的:)n/v意味着没有值。
表1
年份-类别:项目-雇员-1月(天数)-2月
2018 -项目-苹果公司- John N/6-7
2018年项目Apple = n/v
2017年提案-香蕉·提姆·C-8
2017年提案-香蕉- Sena I-9-6
2018 -项目- Kiwi - John N,n/v -6
2018年项目Kiwi Yen T 4 4 5
表2
年份型项目雇员比率
2018年项目苹果公司John N\x{e76f} 30
2018年项目Apple Alex T\ 40
2017年提案香蕉·蒂姆·C
2017年提案-香蕉- Sena I- 30
2018年项目Kiwi John N\x{e76f} 10
2018年项目Kiwi Yen T\ 40
我可以使用SUMPRODUCT(),如果我有相同的利率和天数表;
如果两列位于同一表中,则我使用的公式是:
=IFERROR( D2)(TableType="Project")(TableJan>0))*(TableRate*TableJan),"")
但是对于两个单独的表,它不返回正确的值。
提前感谢
发布于 2018-04-29 22:46:35
我的第一反应是建议根据工作表编写SQL查询:
SELECT Table1.Year, Table1.Type, Table1.Project, Table1.Employee,
SUM(Table1.[Jan(days)] * Table2.Rate) AS SumJan,
SUM(Table1.[Feb(days)] * Table2.Rate) AS SumFeb,
...
FROM Table1
INNER JOIN Table2
ON Table1.Year = Table2.Year
AND Table1.Project = Table2.Project
AND Table1.Employee = Table2.Employee
WHERE Table1.Year = 2018 AND Table1.Type = 'Project'
GROUP BY Table1.Year, Table1.Type, Table1.Project, Table1.Employee
但是,您是在Mac上,所以使用ADO和CopyFromRecordset
不在。也许,通过ODBC和Microsoft,这是可能的。
或者,您可以将第二个工作表中的所有数据加载到一个Scripting.Dictionary
中(这里是Mac的替代部分)。然后,您可以编写一个类似于以下内容的函数:
Option Explicit
Dim dict As Dictionary
Sub FillDictionary()
Set dict = New Dictionary
' load dictionary from table 2
Dim rows As Variant
rows = Table2.Range("A2").CurrentRegion.value
Dim row As Variant, key As String
For Each row In rows
'assuming the first row has the column headers, we don't want to include those in the dictionary
If row(0) <> "Year" Then
key = Join(Array(row(0), row(1), row(2), row(3)), "_")
dict(key) = row(4)
End If
Next
End Sub
Function GetSumRate(Year As Integer, RowType As String, Project As String, Employee As String, Days As Integer)
If dict Is Nothing Then FillDictionary
Dim key As String
key = Join(Array(Year, RowType, Project, Employee), "_")
If dict.Exists(key) Then GetSumRate = dict(key) * Days
End Function
然后,可以从工作表单元格调用函数:
=GetSumRate(Table[Year], Table[Type], Table[Project], Table[Employee], Table[Jan])
https://stackoverflow.com/questions/50091029
复制相似问题