6 種簡單方法刪除 Excel 中的空行(逐步教學)
然後將以下代碼之一複製並粘貼到新的空白模塊中。
代碼 1:刪除活動工作表中的空行
Sub RemoveBlankRows()
'UpdatebyExtendoffice
Dim wsheet As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the worksheet variable to the active sheet
Set wsheet = ActiveSheet
' Get the last row of data in the worksheet
lastRow = wsheet.Cells(wsheet.Rows.Count, 1).End(xlUp).Row
' Loop through each row in reverse order
For i = lastRow To 1 Step -1
' Check if the entire row is blank
If WorksheetFunction.CountA(wsheet.Rows(i)) = 0 Then
' If the row is blank, delete it
wsheet.Rows(i).Delete
End If
Next i
End Sub
代碼 2:刪除選擇範圍中的空行
Sub RemoveBlankRowsInRange()
'UpdatebyExtendoffice
Dim sRange As Range
Dim row As Range
' Prompt the user to select a range
On Error Resume Next
Set sRange = Application.InputBox(prompt:="Select a range", Title:="Kutools for Excel", Type:=8)
' Check if a range is selected
If Not sRange Is Nothing Then
' Loop through each row in reverse order
For Each row In sRange.Rows
' Check if the entire row is blank
If WorksheetFunction.CountA(row) = 0 Then
' If the row is blank, delete it
row.Delete
End If
Next row
Else
MsgBox "No range selected. Please select a range and run the macro again.", vbExclamation
End If
End Sub
最新发布
- 
          战棋天下:英雄崛起2025 2025-05-14 23:05:26
- 
          《像素物语》跨次元庆典:2025春之像素重构计划暨全服玩家共创盛典 2025-04-28 09:52:41
- 
          存私房钱,合法吗? 2025-09-29 08:48:24
- 
          【2025春季嘉年华】超级匹配王全民狂欢盛典 - 智趣连线挑战赛火热开启! 2025-04-27 10:02:33
- 
          星梦芭蕾:璀璨星途·跨次元芭蕾盛宴暨2025全球舞者荣耀挑战季 2025-06-14 23:20:37
- 
          《幸运捕鱼》2025夏季狂欢盛典——海底宝藏大冒险限时开启! 2025-06-03 21:45:07
- 
          修真世界之神力时代:问道飞升,神力觉醒 2025-07-05 12:26:43
- 
          暴走萌部落2:2025年5月18日开启的萌宠大作战狂欢节 2025-05-18 14:14:27
- 
          异世轮回录:时空裂隙的觉醒——跨次元冒险者集结令! 2025-04-17 14:53:38
- 
          《战姬天下》2025年盛夏狂欢庆典:战姬集结,荣耀之战开启! 2025-06-30 22:09:06
