我有700.000+行的大表(部件),其中部件属于具有唯一ID的计算机。
ID | Part | Final Category | Part Cost Price
在另一张表(机器成本价格)中,我有一个包含机器ID的列表,我想检查其完整性(以确保我没有遗漏任何东西/什么都没有出错)。
ID | Total costs
如何有效地检查我是否在“机器成本价格”表中包含了“零件”表中的所有ID - 如果我错过了,请将其添加到底部?
我已经尝试了一个foreach循环,但是这导致我的excel立即崩溃。
任何帮助都会受到关注:)
答案 0 :(得分:0)
由于您的要求是多部分:
第一部分可以用表格公式轻松解决,所以我将重点关注第二部分for each
循环失控。
要解决,我会:
将700000台机器的列表复制到新选项卡:
Sheets("Parts").Range("A1:A700000").copy Destination:=Sheets("newtab").range("A1")
使用.RemoveDuplicates
对象的Range
方法中内置的Excel格式对列表进行重复数据删除:
Sheets("newTab").Range("A1:A700000").RemoveDuplicates(1,xlNo)
现在你可以For Each
这个更小的范围,或者你可以在那里抛出一个公式。
Dim machineCell As Range
'Loop through each cell in the dedup range
For Each machineCell In Sheets("newtab").Range("A1:A" & Sheets("newtab").Range("A900000").End(xlUp).Row()).Cells
'using the .find method of the range object, check for the machine value in the machine worksheet
Set test = Range("A1:A5").Find(machineCell.Value)
If Not test Is Nothing Then
'If test is a range that is set, then we found it.
'So update the column next to our machine cell to "found"
machineCell.Offset(0, 1).Value = "found"
End If
Next machineCell