excel - 删除连续重复
问题描述
我想删除连续的重复但不是连续的空白行,但它也在删除连续的空白单元格。这是我的代码:
Sub Dupl()
Dim i As Long
Dim y As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws
For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 3 Step -1
If .Cells(i, 1).Value = .Cells(i - 1, 1).Value Then
If .Cells(i, 1).Value = " " Then
GoTo y
End If
.Rows(i).Delete
y:
End If
Next i
End With
End Sub
解决方案
您必须使用该IsEmpty()
函数来检查单元格是否为空或包含值。空格被认为是一个值。
For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 3 Step -1
If .Cells(i, 1).Value = .Cells(i - 1, 1).Value Then
If Not IsEmpty(.Cells(i, 1).Value) Then
.Rows(i).Delete
End If
End If
Next i
推荐阅读
- firebase - Flutter Web Firebase 身份验证问题
- android - Android 设备中的 React-native 0.63 版本性能问题
- amazon-web-services - 使用 Cloudformation 为 EBS 快照创建 Cloudwatch 事件
- sql - 用于删除重复(连续)记录的 SQL,但将最小日期存储在开始日期和最大日期作为结束日期
- python - 如何允许用户点击文章中的单词并在 Django 中升级文章模型?
- ios - 从列表中选择多个项目并在 SwiftUI 中更改它们的颜色
- karate - json中的字符串替换不适用于复杂对象
- excel - 在 Excel 中,我的下拉选择如何更改隐藏或未隐藏的列?
- javascript - 在Javascript Map函数中获取中间数组
- apache-spark - 局部级别 PROCESS_LOCAL 的数据局部性如何在启用动态分配的 Spark 中工作