我正在尝试编写一些比较大型列表的内容,如果它们是字符串匹配,那么它会将该字符串复制到另一个列表中。所以我想尽可能地使它成为通用的,这意味着文件中的页数将是未知的,并且每个表中的值的数量将是~800。这是我到目前为止所拥有的。它运行并做我想要的但我注意到它有时会创建部分的双重条目,这会导致excel无法响应。使循环更小可以消除双重条目,但这不是必需的。任何帮助巩固这一点将不胜感激。
Private Sub CommandButton1_Click()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
Worksheets("Parts in common").Range("A12:AH1000").ClearContents
x = 2
w = 2
For Each sheet In Worksheets
If sheet.Name <> TextBox1.Text And sheet.Name <> "Parts in common" Then
w = 2
For y = 2 To 800
For i = 2 To 800
If sheet.Cells(i, 2).Value = Worksheets(TextBox1.Text).Cells(y, 2).Value Then
Worksheets("").Cells(w + 10, x).Value = sheet.Cells(i, 2).Value
Worksheets("").Cells(w + 10, x + 1).Value = sheet.Cells(i, 3).Value
Worksheets("").Cells(w + 10, x + 2).Value = sheet.Cells(i, 16).Value
w = w + 1
End If
Next i
Next y
End If
x = x + 3
Next sheet
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True