Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 比较两张图纸中整行的宏_Excel_Vba - Fatal编程技术网

Excel 比较两张图纸中整行的宏

Excel 比较两张图纸中整行的宏,excel,vba,Excel,Vba,我正在寻找可以执行以下操作的宏: 1) 查看MECH_COMBINED(机械组合)表中是否存在与COMPONENTS(部件)表中的信息完全相同的行。(在MECH_组合中大约有7000行,在COMPONENTS中有20000行,每个表都有列,列的名称都相同) 2) 如果MECH_COMBINED中存在行,则高亮显示COMPONENTS(零部件)表中的整行,并创建第三张具有不同行的表(如果不可能,则第三张表可以具有相同的高亮显示行) 我希望这是一个可能的宏?我现在使用的宏运行速度太慢,最终冻结exc

我正在寻找可以执行以下操作的宏:

1) 查看MECH_COMBINED(机械组合)表中是否存在与COMPONENTS(部件)表中的信息完全相同的行。(在MECH_组合中大约有7000行,在COMPONENTS中有20000行,每个表都有列,列的名称都相同)

2) 如果MECH_COMBINED中存在行,则高亮显示COMPONENTS(零部件)表中的整行,并创建第三张具有不同行的表(如果不可能,则第三张表可以具有相同的高亮显示行)

我希望这是一个可能的宏?我现在使用的宏运行速度太慢,最终冻结excel

Sub Test() 
Application.ScreenUpdating = False 
Dim bottomA1 As Integer bottomA1 = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row Dim c As Range 
Dim bottomA2 As Integer bottomA2 = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row Dim x As Integer For Each c In Sheets("Sheet2").Range("A1:A" & bottomA2) 
For x = bottomA1 To 2 Step -1 If Cells(x, 1) = c Then Cells(x, 1).EntireRow.Interior.Color = 255 End If Next x Next c Application.ScreenUpdating = True 
End Sub

提前感谢:)

以及以下内容:请将您的代码放入问题中,在那里可以对其进行格式设置以确保其易读性。我尝试过这样做,但收到以下错误消息“运行时错误'9':下标超出范围”,它也会使我的excel崩溃
The highlight differs between Excel Versions.  Record a macro that highlights then modify 
and insert it.  Here is a rough macro hopely it is what you want.

Sub macro1()
n = 0
For i = 1 To Sheets("MECH_COMBINED").Cells(Rows.Count, "A").End(xlUp).Row
    For j = 1 To Sheets("COMPONENTS").Cells(Rows.Count, "A").End(xlUp).Row
        For k = 1 To 51 'A to BI
            If Sheets("MECH_COMBINED").Cells(i, k) = Sheets("COMPONENTS").Cells(j, k) Then
                If notequal = 0 Then
                    If k = 51 Then

                        'Highlight Row in Sheets("COMPONENTS")

                        'copy complete row
                        n = n + 1
                        For m = 1 To 51
                            Sheets("Sheet3").Cells(n, m) = Sheets("MECH_COMBINED").Cells(i, m)
                        Next

                        'highlight complete row in Sheets("Sheet3")

                    End If
                End If
            Else
                notequal = 1
            End If
        Next k
        notequal = 0
    Next j
Next i
End Sub