Excel VBA 如何将 A 列空白行移到最后
要将 A 列中的空白行排到后面,您可以使用以下 VBA 代码:
Sub SortBlankRowsToBottom()
Dim lastRow As Long
Dim i As Long
lastRow = Cells(Rows.Count, 1).End(xlUp).Row ' 获取 A 列的最后一行
For i = lastRow To 2 Step -1 ' 从最后一行开始向上循环
If Cells(i, 1).Value = '' Then ' 如果当前单元格内容为空
Rows(i).Cut ' 剪切当前行
Rows(lastRow + 1).Insert Shift:=xlDown ' 将剪切的行插入到最后一行的下一行
lastRow = lastRow - 1 ' 更新最后一行的值
End If
Next i
End Sub
请按照以下步骤使用该代码:
- 打开 Excel 文件并按下
Alt + F11进入 Visual Basic Editor。 - 在 Project 窗格中,找到并双击需要排序的工作表。
- 在代码窗口中,粘贴上述代码。
- 点击运行按钮(或按下
F5键)来执行代码。
这将把 A 列中的空白行排到后面。
原文地址: https://www.cveoy.top/t/topic/JTH 著作权归作者所有。请勿转载和采集!