find一个通用名称

对于同一家公司拥有许多不同名称的大型数据库,我有一些问题。 基本上,我要做的是find代表公司X的所有名称,并将它们更改为“X”。

这样,如果详细名称是“X SL”或“Shipment Regarder ASL”或“oubiyubib(2)”,并且我们知道所有这三个代表公司“X”,我必须寻找他们,并用手改变它们。 还有一些名为“NISA”的意思是代表公司所在的行业,因为有时候我要处理的文件是错误的。

为了解决这个问题,我创build了一个存储所有公司所有已知名称的Excel,然后相应地replace列表中的名称。 存储数据的结构如下所示:

图像绘制 所以第一列有“NISA”,第二列有公司的通用名称,而后面的列是公司的已知名称。 全名列表按字母顺序排列,用“1”表示。

然后,有“INDICE”详细说明三个字母组合的第一个实例出现的行。 这样,以“3SU”开始的名字在第28行中。“INDICIE 2”是详细描述“INDICE”中的第一个字母,因此是索引的索引。 这意味着以“A”开头的“INDICE”中的第一行将在第39行。

所有这一切的主要原因是因为数据库在某些情况下迅速增长到包含超过25万行和超过100列,而且因为有时“3MSA”与“3MSL”是完全不同的公司,所以事情必须逐字逐句检查它是哪个适当的通用名称。

所以大部分的代码是这样的:

Dim listRow As Long, searchRow As Long Dim searchedName As String, genericName As String Dim problem As Boolean problem = False listRow = 2 searchRow = 2 searchedName = "" genericName = "" Do While Cells(listRow, colmnNames) <> "" searchedName = UCase(Cells(listRow, colmnNames)) searchRow = 0 'This part compares if it's looking again for the same name. If it is, it'll just copy the previous results If Cells(listRow, colmnNames) = Cells(listRow - 1, colmnNames) Then Cells(listRow, colmnResults) = Cells(listRow - 1, colmnResults) Cells(listRow, colmnRestNisa) = Cells(listRow - 1, colmnRestNisa) Cells(listRow, errorsA) = Cells(listRow - 1, errorsA) Cells(listRow, errorsB) = Cells(listRow - 1, errorsB) Else Cells(listRow, colmnNames).Select searchRow = IndexRunner(searchedName) '" IndexRunner " will return the row it will have to start looking, if it's 0 then it means the starting letter combination doesn't exist If searchRow > 0 Then searchRow = Finder(searchRow, searchedName) '"Finder" will traverse the database row by row, running the columns until it reaches a blank comparing name by name until it finds a match. If it gets outside the starting 3 letter combination, it stops and returns 0, otherwise, it'll return the row where it found the match If searchRow > 0 Then Cells(listRow, colmnResults) = Cells(searchRow, "B") Cells(listRow, colmnRestNisa) = Cells(searchRow, "A") Else GoTo NotFound End If Else NotFound: Cells(listRow, colmnResults) = searchedName Cells(listRow, colmnRestNisa) = Cells(listRow, colmnSectores) Cells(listRow, errorsA) = searchedName Cells(listRow, errorsB) = Cells(listRow, colmnSectores) Cells(listRow, erroresC) = "Not Found" problem = True 'This is so there'll be a popup at the end of the loop. End If End If listRow = listRow + 1 Loop 

因为代码以“只有名字的前三个字母相符”为中心,所以我可以大大缩短处理时间,但是通过一个五万长的名单仍然需要将近一个小时,所以在这一点上,我想知道是否有任何方法可以让这个在VBA更快或者只是以其他方式来构build所有这一切。

注意:我无法访问其他软件,我在哪里工作,他们有严格的“不允许”的规则添加任何东西到计算机,所以我坚持与Excel VBA,直到上面有人得到一个提示。

一开始,如果你想加快你的代码,你可以使用这个代码片段:

 Application.DisplayAlerts = False Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.EnableEvents = False Application.Calculation = xlManual 

把它放在你的Dim部分之后,并在代码的末尾放入相同的片段,并分别将值更改为true xlAutomatic

 Application.DisplayAlerts = True Application.ScreenUpdating = True Application.DisplayStatusBar = True Application.EnableEvents = True Application.Calculation = xlAutomatic 

在我的情况下,它提高了代码的速度。 如果您跳过DisplayAlerts行来显示警报,以防出现这种情况,我不知道性能如何变化。

如果你也想重构你的代码,那么需要更多的时间。