excel - 如果单元格 ("D(j):H(j)") 只有值 0,则删除行
问题描述
有人可以帮我吗?在 C 列中,单个单元格最初是空的,并且代码在该部分中有效。在 C 列中有几个空单元格的部分中,代码不起作用。关于“lastrow2”或代码的其他位置,我究竟需要改变什么才能达到预期的目标?
lastrow2 = Cells(Cells.Rows.Count, "C").End(xlUp).Row
For j = lastrow2 To 1 Step -1
If (Cells(j, 4) = 0 And Cells(j, 5) = 0 And Cells(j, 6) = 0 And Cells(j, 7) = 0 And Cells(j, 8) = 0 And Cells(j, 9) = 0) Then
Rows(j).Delete
End If
Next j
非常感谢您的支持。:)
最好的问候, 巴马内
解决方案
测试列C可能太浅。这个:
Sub trewq()
ActiveSheet.UsedRange
Set r = ActiveSheet.UsedRange
lastrow2 = r.Rows.Count + r.Row - 1
For j = lastrow2 To 1 Step -1
If (Cells(j, 4) = 0 And Cells(j, 5) = 0 And Cells(j, 6) = 0 And Cells(j, 7) = 0 And Cells(j, 8) = 0 And Cells(j, 9) = 0) Then
Rows(j).Delete
End If
Next j
End Sub
可能会更好......我们正在检查D到I列
推荐阅读
- c++ - 错误:'const'之前的预期主表达式和错误:'const'之前的预期')'
- reactjs - 如何通过单元测试和功能测试来衡量 webapp 中的代码覆盖率
- node.js - 如何使用node js通过url在浏览器中呈现日志文件?
- c# - 显示来自 OracleConnection C# 的 .sql 输出
- asp.net - 一种防止在多行文本框中重复输入的方法
- ios - 如何避免在表格视图中突出显示两个单元格?
- xamarin - Java.Net.SocketException:recvfrom 失败:Xamarin 表单中的 ECONNRESET
- c++ - qt - 在具有不同父级的类中的对象之间发送信号
- python-3.x - ffmpeg 将一张图片转换为视频
- vb.net - WebBrowser顶部具有透明背景的图片框