简体   繁体   English

Excel VBA有条件地通过查找值删除重复项

[英]Excel VBA Conditionally Remove Duplicates By Lookup Value

I wasn't quite sure how to title this question, but it's as concise as I could think of. 我不太确定如何为这个问题加上标题,但是我想得很简洁。 Sorry if it's junk. 对不起,如果是垃圾。

I have a list created on Sheet2 based on info from Sheet1. 我有一个基于Sheet1的信息在Sheet2上创建的列表。 What I'd like to do is examine ColumnA and remove duplicate rows if the matching value on Sheet1 ColumnB's offset ColumnE doesn't equal "SUB-ASSY". 我想做的是检查ColumnA,如果Sheet1 ColumnB的偏移量ColumnE上的匹配值不等于“ SUB-ASSY”,则删除重复的行。

Basically: Find the value from Sheet2, ColumnA on Sheet1, ColumnB. 基本上:从Sheet1的Sheet2的ColumnA中找到值,ColumnB。 Get the value from Sheet1, ColumnE If it does NOT match "SUB-ASSY", delete any duplicates on Sheet2 This should leave one instance of all non-subassembly entries and leave subassemblies alone. 从Sheet1的ColumnE中获取值,如果该值与“ SUB-ASSY”不匹配,则删除Sheet2上的所有重复项。这应保留所有非子装配条目的一个实例,并单独保留子装配。

Does this make any sense? 这有道理吗?

I think I need to do some INDEX/MATCH or VLOOKUP, but I don't know if that'd be the right way to go (or exactly how I'd do it). 我想我需要做一些INDEX / MATCH或VLOOKUP,但是我不知道这是否是正确的方法(或者我该怎么做)。 Does anyone have a good way to do this? 有人有这样做的好方法吗?

I appreciate any help. 感谢您的帮助。 I can include the workbook if needed, but it looks up a bunch of stuff on an sql server, so it might not work correctly if you can't connect. 如果需要,我可以包括该工作簿,但是它会在sql服务器上查找很多内容,因此如果您无法连接,则可能无法正常工作。

Thanks Again, 再次感谢,

-stu -斯图

Are you looking for a general idea on how to do this, or a VBA macro? 您是否正在寻找有关如何执行此操作的一般思路或VBA宏?

One way I'm thinking that could get you going is in your second sheet (which, in the end, will have only unique entries) create a 'helper column'. 我认为可以帮助您解决问题的一种方法是在第二张工作表中(最后只有唯一的条目)创建一个“帮助列”。 Let's say Column F is empty. 假设F列为空。 You can do a simple "if" statement that will check for the value on that row, in column A is in that other sheet. 您可以执行一个简单的“ if”语句,该语句将检查另一张表中A列中该行的值。 If so, return "DUPLICATE" (or some note, "Duplicate, delete", etc.). 如果是这样,则返回“ DUPLICATE”(或某些注释,“ Duplicate,delete”等)。 Then run that down the columns, then sort that whole table by your new column. 然后在各列中运行,然后按新列对整个表进行排序。 This will sort all the duplicate values in one big block, which you can highlight and delete. 这会将所有重复值排序在一个大块中,您可以突出显示并删除它。

It could help if you show a little bit of what the data looks like on your Sheet1 and Sheet2 (can be made up data, doesn't have to be SQL server info). 如果您在Sheet1和Sheet2上显示一下数据的外观(可能是数据,不必是SQL Server信息),可能会有所帮助。

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

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