excel按一列删除重复行,并按另一列时间保留最近的一条记录
时间:2023-06-23 22:09:52
本文介绍excel中根据A列公司名称找出重复的记录,并按照C列时间保留最近的一条记录的方法,希望对大家有所帮助。
A列公司名称,B列公司地址,C列时间。
我想根据A列找出重复的,然后删除那一整行,只留下最近一个记录。
例: A列 B列 C列
北京1公司 北京市西城区 2010-1-1
北京5公司 北京市海淀区 2010-2-2
北京1公司 北京市朝阳区 2010-3-20
北京3公司 北京市东城区 2010-1-20
北京2公司 北京市丰台区 2010-5-1
北京3公司 北京市宣武区 2010-7-1
删除后
北京1公司 北京市西城区 2010-3-20
北京5公司 北京市海淀区 2010-2-2
北京3公司 北京市东城区 2010-7-1
北京2公司 北京市丰台区 2010-5-1
复制代码代码如下:
Sub 删除重复行()
'
'*******数据放在Sheet1并从A1开始
'*******A列放重复的
'*******C列放时间
Sheets("Sheet1").Select
'A列到Z列排序
Columns("A:Z").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, HEADER:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNorma
Range("A1").Select
GoTo tiaoc13
tiaoc1:
If ActiveCell.Offset(0, 2) >= ActiveCell.Offset(1, 2) Then GoTo tiaoc12
ActiveCell.Offset(0, 0).Rows("1:1").EntireRow.Delete Shift:=xlUp
GoTo tiaoc13
tiaoc12: ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Delete Shift:=xlUp
tiaoc13:
Do While ActiveCell.Offset(0, 0) <> ""
If ActiveCell.Offset(0, 0) = ActiveCell.Offset(1, 0) Then GoTo tiaoc1
ActiveCell.Offset(1, 0).Select
Loop
End Sub
录一个宏用上面代码替换,再运行这个宏即可
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Microsoft Excel 教程「52」,如何在 Excel 中保护文件、转换数据类型?
![](https://img.aspxhome.com/file/2023/8/a202678_0s.jpeg)
怎么在Win7开始菜单中添加下载选项?
![](https://img.aspxhome.com/file/2023/29/a251577_0s.jpg)
重装系统后电脑开机遇到0xc000007b蓝屏代码怎么办?
![](https://img.aspxhome.com/file/2023/4/a308548_0s.png)
MS Excel 2016 如何为表格设置多个条件格式?-Excel教程
如何让指定的电脑窗口固定在最前端(始终显示)
![](https://img.aspxhome.com/file/2023/29/a262326_0s.png)
iPhone手机更换电池后出现无法验证此电池是正品?
Windows10系统下虚拟环绕声怎么打开?
![](https://img.aspxhome.com/file/2023/26/a225049_0s.jpg)
火绒安全软件如何限制软件网速?限制软件网速的方法了解一下
![](https://img.aspxhome.com/file/2023/7/a331465_0s.jpg)
哪种U盘启动方式更好
![](https://img.aspxhome.com/file/2023/3/a301994_0s.png)
word2013快速插入数学公式的两种方法介绍
![](https://img.aspxhome.com/file/2023/6/29096_0s.png)
Win10 Build 9901 泄露 改进细节画廊
![](https://img.aspxhome.com/file/2023/29/a252681_0s.jpg)
在ppt中快速绘制出漂亮的放射型背景效果
![](https://img.aspxhome.com/file/2023/10/a346743_0s.jpg)
分别显示差(50)、中(100)、优(150)3个档次
wps office的文件怎么打开是乱码?
![](https://img.aspxhome.com/file/2023/0/a168370_0s.jpg)
Win10更新20H2卡住怎么办?
![](https://img.aspxhome.com/file/2023/1/a280822_0s.jpg)
Win10专业版进入后频闪怎么办?Win10登录后闪屏解决方法
![](https://img.aspxhome.com/file/2023/26/a222986_0s.jpg)
Mac运行Win 10画面出问题怎么修复?
![](https://img.aspxhome.com/file/2023/3/a195563_0s.jpg)
Word中批量删除节信息的方法
![](https://img.aspxhome.com/file/2023/5/17995_0s.jpg)
Windows 10中的WMI Provider Host (WmiPrvSE.exe)进程是什么?
![](https://img.aspxhome.com/file/2023/30/a262739_0s.jpg)