Excel o你所拥有的)。我将完全使用VBA数组,而不是对工作表进行多次调用。我将创建一个类对象,其中包含每个块(组、零件和单元的集合)的信息,并在字典中收集这些对象。它的执行速度将比您制定的流程快得多,并且在将来应该更易于维护。嗨,Ron,感谢您的快速回复。我在V
Excel o你所拥有的)。我将完全使用VBA数组,而不是对工作表进行多次调用。我将创建一个类对象,其中包含每个块(组、零件和单元的集合)的信息,并在字典中收集这些对象。它的执行速度将比您制定的流程快得多,并且在将来应该更易于维护。嗨,Ron,感谢您的快速回复。我在V,excel,vba,Excel,Vba,o你所拥有的)。我将完全使用VBA数组,而不是对工作表进行多次调用。我将创建一个类对象,其中包含每个块(组、零件和单元的集合)的信息,并在字典中收集这些对象。它的执行速度将比您制定的流程快得多,并且在将来应该更易于维护。嗨,Ron,感谢您的快速回复。我在VBA中尝试了你的建议,但似乎无法奏效。由于我需要进一步学习字典和数组,你能帮助一个新手吗?@Korosuke你会发现已故的Chip Pearson网站是一个非常宝贵的资源。对于您的具体问题,我建议您选择上的主题和这篇介绍性文章。但是还有更多的东
o你所拥有的)。我将完全使用VBA数组,而不是对工作表进行多次调用。我将创建一个类对象,其中包含每个块(组、零件和单元的集合)的信息,并在字典中收集这些对象。它的执行速度将比您制定的流程快得多,并且在将来应该更易于维护。嗨,Ron,感谢您的快速回复。我在VBA中尝试了你的建议,但似乎无法奏效。由于我需要进一步学习字典和数组,你能帮助一个新手吗?@Korosuke你会发现已故的Chip Pearson网站是一个非常宝贵的资源。对于您的具体问题,我建议您选择上的主题和这篇介绍性文章。但是还有更多的东西对你有用。
let
//Change table names to your actual table names
Source = Excel.CurrentWorkbook(){[Name="Database"]}[Content],
Source2 = Excel.CurrentWorkbook(){[Name="Table"]}[Content],
//Remove Block Totals
//It will be easier to just calculate them later
#"Filtered Rows" = Table.SelectRows(Source2, each ([Column1] <> null and [Column1] <> "")),
//Join with Group Column to match up with Column1
//then expand the nested join
grpCol = Table.AddJoinColumn(#"Filtered Rows","Column1",Source,"Column1","with Group"),
#"Expanded with Group" = Table.ExpandTableColumn(grpCol, "with Group", {"Column2"}, {"with Group.Column2"}),
//Rename columns for clarity
#"Renamed Columns" = Table.RenameColumns(#"Expanded with Group",{
{"Column1", "Part"},
{"Column2", "Block"},
{"Column3", "Units"},
{"with Group.Column2", "Group"}
}),
//Group by "Block" and "Group"
//Calculate Subtotal for each Group (within each Block)
//Add Index column to subTable -- to be used so Group Name and Total for group only appear on first line
#"Grouped Rows" = Table.Group(#"Renamed Columns", {"Block", "Group"}, {
{"Amt", each List.Sum([Units]), type number},
{"All", each _, type table [Part=text, Block=text, Units=number, Group=text]},
{"Idx", each Table.AddIndexColumn(_,"Index",0,1)}
}),
//Remove unneeded column of tables and Expand the column of tables with Index column added
#"Removed Columns1" = Table.RemoveColumns(#"Grouped Rows",{"All"}),
#"Expanded Idx" = Table.ExpandTableColumn(#"Removed Columns1", "Idx", {"Part", "Units", "Index"}, {"Part", "Units", "Index"}),
//Add columns for Group and Group Total, showing only on the first entry of the Group Name
//then remove unneeded columns
#"Added Custom1" = Table.AddColumn(#"Expanded Idx", "Group.1", each if [Index] = 0 then [Group] else null),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Group Total", each if [Index] = 0 then [Amt] else null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Group", "Amt", "Index"}),
#"Renamed Columns1" = Table.RenameColumns(#"Removed Columns",{{"Group.1", "Group"}}),
//Group by Block
//Add Block subtotal row to each block group
#"Grouped Rows1" = Table.Group(#"Renamed Columns1", {"Block"}, {
{"blockGroup", each _, type table [Block=text, Part=text, Units=number, Group=nullable text, Group Total=nullable number]},
{"Block Total", each Table.InsertRows(_, Table.RowCount(_),
{[Block=null, Part=[Block]{0} & " Total", Units=List.Sum([Units]), Group=null,Group Total=null]})}
}),
//Remove unneeded column and expand the table
#"Removed Columns3" = Table.RemoveColumns(#"Grouped Rows1",{"blockGroup", "Block"}),
#"Expanded Block Total" = Table.ExpandTableColumn(#"Removed Columns3", "Block Total", {"Block", "Part", "Units", "Group", "Group Total"}, {"Block", "Part", "Units", "Group", "Group Total"})
in
#"Expanded Block Total"