简体   繁体   English

跨多个工作表的独特数据整合

[英]Unique data consolidation across multiple Worksheets

I have six worksheets which I want to take the unique id's from a specific column and consolidate them into 1 master (in order to do some analysis and different data representation). 我有六个工作表,我想从特定列中获取唯一的ID,并将其合并为1个主表(以便进行一些分析和不同的数据表示)。

The data all starts from the same cell C17, but ends at different rows (ie C180, C268, etc). 数据全部从相同的单元格C17开始,但在不同的行(即C180,C268等)处结束。 I want to be able to consolidate the unique ids from all six spreadsheets weekly. 我希望能够每周合并所有六个电子表格中的唯一ID。

Is there a solution that will not use array formulas as that SERIOUSLY causes a problem due to the sheer number of rows and resources needed to calculate the list. 是否存在不使用数组公式的解决方案,因为由于行数和计算列表所需的资源过多,会严重导致问题。 VBA automation is preferred where the cell ranges for consolidation can be dynamic and the sheet names are referenced from specific cells in the master sheet (it will never be deleted or altered to the extent of the six others)? 如果要合并的单元格范围可以是动态的,并且工作表名称是从主表中的特定单元格引用的(永远不会删除或更改为其他六个范围),则VBA自动化是首选

So, I would run a macro which will consolidate all the data based off either a named range or specific cells with the sheet names & ranges in them (using indirect to use those strings) and paste that into a new range. 因此,我将运行一个宏,该宏将基于命名的范围或其中包含工作表名称和范围的特定单元格(使用间接使用这些字符串)合并所有数据,并将其粘贴到新的范围中。

UDF's would be acceptable as well, I just do not want Excel to "freeze" doing calculations. UDF也可以接受,我只是不希望Excel“冻结”进行计算。

BTW, I did read Getting unique values in Excel by using formulas only but those solutions only work if the data is on the same sheet or under very specific conditions. 顺便说一句,我确实读过仅通过使用公式在Excel中获取唯一值,但是这些解决方案仅在数据位于同一张纸上或在非常特定的条件下才有效。 Also the array formulas would not work efficiently since my data is literally thousands of rows long. 另外,由于我的数据实际上是数千行,因此数组公式不能有效地工作。

Edit: 编辑:

Here's a test macro I used to get data from one sheet, but the problem is I can't use dynamics nor add the rest of the names from the other sheets because the range I copy it to I can't pull the first blank cell after the id's copied. 这是我用来从一张工作表中获取数据的测试宏,但问题是我无法使用动态功能,也无法添加其他工作表中的其余名称,因为我将其复制到的范围无法提取第一个空白单元格复制ID后。

Sub ConsolidateDATA()
    'yStr = Evaluate("=ADDRESS(MIN(IF($C$10:$C$9999 = "", ROW($C$10:$C$9999))), 3, 1, 1)")
    'Attempted dynamic range copy ^ - failed
    yStr = "C10"
    Range("Sheet1!$B$5:$B$29").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:="", CopyToRange:=Range(yStr), Unique:=True
End Sub

I have also had successful attempts with array formulas, but unfortunately they are resource intensive that they are REALLY bad solutions. 我也曾成功尝试过数组公式,但不幸的是,它们是资源密集型的,因为它们确实是不好的解决方案。

-- Array formula to combine lists into 1 master -将列表合并为1个主列表的数组公式

=IFERROR(INDEX(INDIRECT($B$6, TRUE), ROWS(B$13:$B14)), IFERROR(INDEX(INDIRECT($B$7, TRUE), ROWS(B$13:$B14) - ROWS(INDIRECT($B$6, TRUE))), IFERROR(INDEX(INDIRECT($B$8, TRUE), ROWS(B$13:$B14) - ROWS(INDIRECT($B$6, TRUE)) - ROWS(INDIRECT($B$7))), IFERROR(INDEX(INDIRECT($B$9, TRUE), ROWS(B$13:$B14) - ROWS(INDIRECT($B$6, TRUE)) - ROWS(INDIRECT($B$7)) - ROWS(INDIRECT($B$8))), IFERROR(INDEX(INDIRECT($B$10, TRUE), ROWS(B$13:$B14) - ROWS(INDIRECT($B$6, TRUE)) - ROWS(INDIRECT($B$7)) - ROWS(INDIRECT($B$8)) - ROWS(INDIRECT($B$9, TRUE))), IFERROR(INDEX(INDIRECT($B$11, TRUE), ROWS(B$13:$B14) - ROWS(INDIRECT($B$6, TRUE)) - ROWS(INDIRECT($B$7)) - ROWS(INDIRECT($B$8)) - ROWS(INDIRECT($B$9, TRUE)) - ROWS(INDIRECT($B$10, TRUE))),IFERROR(INDEX(INDIRECT($B$12, TRUE), ROWS(B$13:$B14) - ROWS(INDIRECT($B$6, TRUE)) - ROWS(INDIRECT($B$7)) - ROWS(INDIRECT($B$8)) - ROWS(INDIRECT($B$9, TRUE)) - ROWS(INDIRECT($B$10, TRUE)) - ROWS(INDIRECT($B$11, TRUE))),"")))))))

-- Array formula to get just unique data -数组公式仅获取唯一数据

=INDEX(TotalNameListRangeFromFormulaAbove, MATCH(0, COUNTIF($D$16:D16, TotalNameListRangeFromFormulaAbove), 0))

I think a combination of loops and collections might solve your problem :) 我认为循环和集合的组合可能会解决您的问题:)

http://excelmacromastery.com/Blog/index.php/the-complete-guide-to-collections-in-excel-vba/ http://excelmacromastery.com/Blog/index.php/the-complete-guide-to-collections-in-excel-vba/

 for i = 1 to UBound(worksheetcount, 1)
 for j = 1 to UBound(cellrangecount, 1)
 With CreateObject("scripting.dictionary")
 For Each "Key" In cellrangecount(cellrangecount)
 If Not .Exists(Key) Then .Add Key, Key & "_content"
 Next j
 next i
 End With

I believe this is good enough to get you started on the correct path. 我相信这足以使您开始正确的道路。 I ended up using a dictionary instead of a collection but you can change that if you'd like. 我最终使用字典而不是收藏,但是如果愿意,您可以更改它。 Only minor differences on declarations and adding but essentially the same (anecdotally speaking, there are a couple of huge differences, not that I think it matters here). 声明和添加之间只有细微的差异,但本质上是相同的(从轶事上讲,有一些巨大的差异,我认为这里并不重要)。 Give me some time and I'll return with something more polished/finished than just the "basic idea of how it might work." 给我一些时间,我将返回的内容要比“关于其如何工作的基本概念”更精致/更完善。

link for dictionaries from the same guy (i really love the way this guy elaborates on stuff) 链接来自同一个人的字典(我真的很喜欢这个人对事物的阐述)

http://excelmacromastery.com/Blog/index.php/vba-dictionary/ http://excelmacromastery.com/Blog/index.php/vba-dictionary/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM