excel - 如何使用宏删除excel中的特定行和升档单元格?
问题描述
有人可以帮助我删除 Excel 中的特定行,然后使用宏向上移动单元格吗?例如,我需要删除第 8、14 和 79 行。
在此先感谢您的帮助
解决方案
尝试:
Option Explicit
Sub test()
Dim LastRow As Long, i As Long
With ThisWorkbook.Worksheets("Sheet1") '<- Change sheet name if needed
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row '<- Find lastrow of column A where we assume data appears
For i = LastRow To 1 Step -1 '<- Loop from bottom to top
If i = 8 Or i = 14 Or i = 79 Then '<- If row is 8 or 14 or 79
.Rows(i).EntireRow.Delete '<- Delete row
End If
Next i
End With
End Sub
Pᴇʜ 建议的另一个解决方案(见评论):
Option Explicit
Sub test()
ThisWorkbook.Sheets("Sheet1").Range("8:8,14:14,79:79").EntireRow.Delete
End Sub
另一个解决方案:
Option Explicit
Sub test()
With ThisWorkbook.Sheets("Sheet1")
Union(.Rows(8), .Rows(14), .Rows(79)).Delete Shift:=xlUp
End With
End Sub
推荐阅读
- arrays - 用特殊顺序的字符串填充二维数组
- c - 父进程,创建2个子进程并使用管道发送数据
- output - GCS 存储桶中的 Google Cloud Composer DAG 相对目录
- c# - 如何在 C# 中读取以 view-source 开头的 URL
- discord.js - Collection#find:改为传递函数
- scala - 光滑的多对一映射
- reactjs - TypeError:无法读取未定义的属性“拥有”
- java - 如何使用 VoiceResponse 拨打电话?特维利奥
- video - 使用 Raspbian Stretch 在 Raspberry Pi 3 上使用 gstreamer 播放视频
- python - 装饰器中的控制流