如何删除范围内的整行(如果为空)?



我有代码将工作表从一个工作簿复制到另一个工作簿,然后它用值替换复制的信息。

我需要删除A列范围内的任何空白行。删除空行的说明不起作用。

我搜索了,但没有找到任何解释。

Private Sub Template1()
Dim FName4 As String
Dim NewBook4 As Workbook
Dim wbNew4 As Workbook
Dim wks4 As Worksheet
Dim Release As String
Dim FPath As String
Dim RDate As String

FPath = InputBox("Please enter file path to save files to")
Release = InputBox("Enter release number")
RDate = InputBox("Enter release date in format yyyymmdd")
Application.ScreenUpdating = False

FName4 = RDate & " Release " & Release & " Template" & ".xlsx"

Set NewBook4 = Workbooks.Add

ThisWorkbook.Sheets("Template").Copy Before:=NewBook4.Sheets(1)

For Each wks4 In NewBook4.Worksheets
With wks4.UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False

Next wks4
NewBook4.Worksheets("Template").Range("A2:A12").Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete shift:=xlUp
NewBook4.SaveAs Filename:=FPath & "" & FName4, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

Application.ScreenUpdating = True

End Sub

替换这个: Selection.SpecialCells(xlCellTypeBlanks(.EntireRow.Delete shift:=xlUp

通过这个: Selection.Worksheet.UsedRange.SpecialCells(xlCellTypeBlanks(.EntireRow.Delete shift:=xlUp

这应该对你有用!

相关内容

最新更新