Loops 嵌套For循环的合并

Loops 嵌套For循环的合并,loops,for-loop,Loops,For Loop,我试图写一些东西来比较一个大的列表,如果它们的字符串匹配,那么它会将该字符串复制到另一个列表。所以我想让它尽可能通用,这意味着文件中的表数未知,每个表中的值数为~800。这是我到目前为止所拥有的。它运行并执行我想要的操作,但我注意到它有时会创建两个零件条目,并导致excel变得无响应。使循环变小可以消除双条目,但这不是所希望的。如有任何帮助,我们将不胜感激 Private Sub CommandButton1_Click() Application.Calculation = xlCalcul

我试图写一些东西来比较一个大的列表,如果它们的字符串匹配,那么它会将该字符串复制到另一个列表。所以我想让它尽可能通用,这意味着文件中的表数未知,每个表中的值数为~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
Private子命令按钮1\u单击()
Application.Calculation=xlCalculationManual
Application.ScreenUpdating=False
Application.EnableEvents=False
工作表(“通用零件”).范围(“A12:AH1000”).清晰目录
x=2
w=2
对于工作表中的每张图纸
如果sheet.Name TextBox1.Text和sheet.Name为“公共部分”,则
w=2
对于y=2到800
对于i=2到800
如果sheet.Cells(i,2).Value=工作表(TextBox1.Text).Cells(y,2).Value,则
工作表(“”).Cells(w+10,x).Value=sheet.Cells(i,2).Value
工作表(“”).Cells(w+10,x+1).Value=sheet.Cells(i,3).Value
工作表(“”)。单元格(w+10,x+2)。值=工作表。单元格(i,16)。值
w=w+1
如果结束
接下来我
下一个y
如果结束
x=x+3
下一页
Application.Calculation=xlCalculationAutomatic
Application.ScreenUpdating=True
Application.EnableEvents=True