Excel / VBA:如何保持包含第一个var的第一行并删除其余的重复?

问题:

我在Excel中有大约5万行。 每一行都包含一个单词domain = [a-Z0-9],其中[a-Z0-9]是一串数字和文字(如GUID)的占位符。 这个域ID让我们调用abc123它是唯一的。 但是,在50,000行中,它不是表的唯一键,所以我需要通过删除域ID = abc123的所有其他行来使其唯一。 但是我必须为所有的域做这个,所以我不能具体。 我需要一个脚本来解决这个问题。 域ID总是在同一列中,并有许多不同的域ID重复自己。

样品

第2栏
abunchofstuff3123123khafadkfh23k4h23kh * DomainID = abc123 *

伪代码

//Whenever there is a value for domain in row i col 2 //does it already exist in ListOfUniqueDomains? //if so then remove this row //else add to the ListOfUniqueDomains 

Excel / VBA如何做到这一点?

更新的答案所以我真的很喜欢使用数据透视表的想法,但我仍然必须提取域ID,所以我想我会在这里发布的解决scheme的部分。 我实际上偷了一些其他网站上的function,但我失去了原来的职位,给予适当的信贷。 所以请原谅我,如果那个人是你,但是要给自己一个轻拍,如果你在我家附近,我会给你买午餐。

所以在我的情况下,我有2个delimeters(=,&)的stringdomain=abc123&embedded在一个更长的string。 所以要提取域ID我做了以下。

  Public Function extract_value(str As String) As String Dim openPos As Integer Dim closePos As Integer Dim midBit As String On Error Resume Next openPos = InStr(str, "=") 'get the position of the equal sign On Error Resume Next closePos = InStr(str, "&") ' get the position of the & On Error Resume Next midBit = Mid(str, openPos + 1, closePos - 1) 'get the string that is between equal sign and before '&' however this seems 'greedy and so it 'picked up the last '&'.I used split to get the first occurrence 'of '&' because that was how my string was designed. Dim s As String s = Split(midBit, "&")(0) extract_value = s End Function 

VBA是一个好主意吗?

谢谢

我已经做了一些相当大的文件(50k行),我只需要提取唯一的元素。 我所做的很简单:使用数据透视表。 这样你甚至不需要VBA,但是如果你想进一步处理它,更新表格和提取数据还是很简单的。

我真正喜欢这种方法的原因之一是它同时非常容易和强大。 你没有循环或algorithm来编写,在Excelfunction中就是这样。

在这里输入图像说明