- ·上一篇:excel如何算总毛利
- ·下一篇:excel如何把格子统一调大
excel表中如何去掉重复值
1.Excle中如何删除两个表中相同的行(附件)
操作步骤: 1、打开Excel文件,按“Alt+F11”进入VBE编辑环境; 2、“插入”-》“模块”; 3、在右侧的代码编辑区域粘贴以下代码: Option Explicit Sub mark_rept() Application。
ScreenUpdating = False Dim k As Range, c As Range, rngSource As Range Dim strAdd As String With Sheets("sheet2") 。Cells。
Interior。ColorIndex = xlNone Set rngSource = Range(。
[A1], 。Cells(。
[A1]。End(xlDown)。
Row, 1)) End With With Sheets("sheet1") 。 Cells。
Interior。ColorIndex = xlNone For Each k In Range(。
[A1], 。Cells(。
[A1]。End(xlDown)。
Row, 1)) Set c = rngSource。Find(k, LookIn:=xlValues) If Not c Is Nothing Then strAdd = c。
Address Do Range(c, c。Offset(0, 4))。
Interior。Color = RGB(Int((254 * Rnd)), Int((254 * Rnd)), Int((254 * Rnd))) Range(k, k。
Offset(0, 4))。Interior。
Color = RGB(Int((254 * Rnd)), Int((254 * Rnd)), Int((254 * Rnd))) Set c = rngSource。FindNext(c) Loop While Not c Is Nothing And c。
Address strAdd End If Next End With Application。ScreenUpdating = True End Sub Sub delt_rept() Application。
ScreenUpdating = False Dim a As Range, b As Range With Sheets("sheet1") For Each a In Range(。 [A1], 。
Cells(。[A1]。
End(xlDown)。Row, 1)) If a。
Interior。ColorIndex xlNone Then Range(a, a。
Offset(0, 4))。Delete Shift:=xlUp Next End With With Sheets("sheet2") For Each b In Range(。
[A1], 。Cells(。
[A1]。End(xlDown)。
Row, 1)) If b。Interior。
ColorIndex xlNone Then Range(b, b。Offset(0, 4))。
Delete Shift:=xlUp Next End With Application。 ScreenUpdating = True End Sub 4、关闭VBE,返回Excel表格界面,添加两个文本框,分别右键指定宏,如附件所示。
使用时,先按“标记重复数据”把重复的数据用背景色标记出来,然后使用“删除重复数据”来删除这些数据。 由于删除数据时记录指针会随着数据的删除而产生偏差,所以点击一次按钮只能删除部分重复数据,可以多次点击以完成删除工作。
特别提醒,使用前注意留一份备份,以防出现意外情况时不至于造成不必要的损失,养成好的备份习惯,有利于保护数据的完整和安全。 祝好~~ 。
2.Excle中如何删除两个表中相同的行(附件)在Excle表格中有
操作步骤: 1、打开Excel文件,按“Alt+F11”进入VBE编辑环境; 2、“插入”-》“模块”; 3、在右侧的代码编辑区域粘贴以下代码: Option Explicit Sub mark_rept() Application。
ScreenUpdating = False Dim k As Range, c As Range, rngSource As Range Dim strAdd As String With Sheets("sheet2") 。Cells。
Interior。ColorIndex = xlNone Set rngSource = Range(。
[A1], 。Cells(。
[A1]。End(xlDown)。
Row, 1)) End With With Sheets("sheet1") 。 Cells。
Interior。ColorIndex = xlNone For Each k In Range(。
[A1], 。Cells(。
[A1]。End(xlDown)。
Row, 1)) Set c = rngSource。Find(k, LookIn:=xlValues) If Not c Is Nothing Then strAdd = c。
Address Do Range(c, c。Offset(0, 4))。
Interior。Color = RGB(Int((254 * Rnd)), Int((254 * Rnd)), Int((254 * Rnd))) Range(k, k。
Offset(0, 4))。Interior。
Color = RGB(Int((254 * Rnd)), Int((254 * Rnd)), Int((254 * Rnd))) Set c = rngSource。FindNext(c) Loop While Not c Is Nothing And c。
Address strAdd End If Next End With Application。ScreenUpdating = True End Sub Sub delt_rept() Application。
ScreenUpdating = False Dim a As Range, b As Range With Sheets("sheet1") For Each a In Range(。 [A1], 。
Cells(。[A1]。
End(xlDown)。Row, 1)) If a。
Interior。ColorIndex xlNone Then Range(a, a。
Offset(0, 4))。Delete Shift:=xlUp Next End With With Sheets("sheet2") For Each b In Range(。
[A1], 。Cells(。
[A1]。End(xlDown)。
Row, 1)) If b。Interior。
ColorIndex xlNone Then Range(b, b。Offset(0, 4))。
Delete Shift:=xlUp Next End With Application。 ScreenUpdating = True End Sub 4、关闭VBE,返回Excel表格界面,添加两个文本框,分别右键指定宏,如附件所示。
使用时,先按“标记重复数据”把重复的数据用背景色标记出来,然后使用“删除重复数据”来删除这些数据。 由于删除数据时记录指针会随着数据的删除而产生偏差,所以点击一次按钮只能删除部分重复数据,可以多次点击以完成删除工作。
特别提醒,使用前注意留一份备份,以防出现意外情况时不至于造成不必要的损失,养成好的备份习惯,有利于保护数据的完整和安全。 祝好~~ 。