大致思路是遍历实验表的数据,然后分别对别原始数据行,两列相同则删除。
下面代码的data_sheet.Rows(i).Delete我默认注释了,你先试运行一下,看看打印输出的行对不对,对的话再把这行的注释去掉,再执行删除就好了。
Sub DeleteRow()
Dim sheet As Worksheet
Set sheet = Application.Worksheets("实验")
Dim data_sheet As Worksheet
Set data_sheet = Application.Worksheets("原始数据")
Dim val1 As String
Dim val2 As String
For row_inx = 2 To sheet.UsedRange.Rows.Count
val1 = sheet.Cells(row_inx, 1).Value
val2 = sheet.Cells(row_inx, 2).Value
For i = 2 To data_sheet.UsedRange.Rows.Count
If val1 = data_sheet.Cells(i, 1).Value And val2 = data_sheet.Cells(i, 2).Value Then
'data_sheet.Rows(i).Delete
Debug.Print "将要删除行:", i
End If
Next
Next
End Sub
效果:
中小企业Excel自动化找林潇,欢迎私信、回复交流。