删除重复行Excel VBA [英] Remove duplicate rows Excel VBA
问题描述
换句话说,我有一个范围为B:F的表。我想要脚本删除重复的行,考虑到每一行,只有列D和E上的值。最后,只有在列D和E上同时具有完全相同的值的行 - 不管其他列 - 将被删除。我该怎么办呢?谢谢
这是一个例子。
确保使用要使用的工作表运行它:
Sub DeleteDupes()
Dim x
对于x =单元格(Rows.CountLarge,D)。End(xlUp).Row到1 Step -1
如果单元格(x,D)=单元格(x,E)然后
'此行删除行:
单元格(x,D)。EntireRow.Delete xlShiftUp
'此行突出显示将被删除的行;
'Cells(x,D)。EntireRow.Interior.Color = RGB(230,180,180)
结束如果
下一个x
End Sub
突出显示结果:
删除结果:
I am writing a script in VBA that would remove duplicate rows in an Excel spreadsheet. However, I want it to delete duplicate rows considering only information in two columns.
In other words, I have a table with the range B:F. I want the script to remove duplicate rows considering, for each row, only the values on columns D and E. In the end, only rows which simultaneously have the exact same values on columns D and E - regardless of other columns - will be removed. How could I go about doing this? Thank you
Here is an example that does this.
Make sure you run it with the sheet you want to use up:
Sub DeleteDupes()
Dim x
For x = Cells(Rows.CountLarge, "D").End(xlUp).Row To 1 Step -1
If Cells(x, "D") = Cells(x, "E") Then
'This line deletes the row:
Cells(x, "D").EntireRow.Delete xlShiftUp
'This line highlights the row to show what would be deleted;
'Cells(x, "D").EntireRow.Interior.Color = RGB(230, 180, 180)
End If
Next x
End Sub
Results of highlighting:
Results of Delete:
这篇关于删除重复行Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!