excel - 删除特定单元格正下方的单元格
问题描述
我正在编写一个脚本来查找一个值并删除该单元格及其正下方的单元格。我最初的想法是使用偏移量,但不确定如何使用。
Dim batch As Range
For Each batch In ActiveSheet.UsedRange
If batch.Value = "Batch" Then batch.Cells.Delete Shift:=xlShiftUp
'Delete cell below all cells containing 'batch'
Next batch
谢谢!
解决方案
利用Resize()
Sub lskdhfdg()
Dim batch As Range
For Each batch In ActiveSheet.UsedRange
If batch.Value = "Batch" Then batch.Resize(2, 1).Delete Shift:=xlShiftUp
Next batch
End Sub
编辑#1
只有 1 行更改:
Sub lskdhfdg2()
Dim batch As Range
For Each batch In ActiveSheet.UsedRange
If InStr(batch.Value, "Batch") > 0 Then batch.Resize(2, 1).Delete Shift:=xlShiftUp
Next batch
End Sub
推荐阅读
- eclipse - 未能执行目标 com.google.appengine:appengine-maven-plugin:1.9.67:devserver
- python - How to create a recursive linked node insertion sort algorithm?
- java - Java minecraft 服务器无法在 linux 虚拟服务器机器上的 IPv4 上运行/侦听
- c - fprintf 不在 ^C 上写入,但在退出时写入
- php - 使用 Laravel 和 AJAX 搜索两个表时出错
- git - Git 排除某些提交和代码更改并将其他提交保持在最前面
- android - 带有地图意图的标记标签
- svm - 具有动态时间规整内核的 SVM
- python - 如何最好地合并来自多个字典的值?
- linux - 使用现有的 iproute2 网络命名空间启动 docker 容器