麻烦运行一个简单的空白行删除

我对macros来说是新手,但是我怀疑其他的东西可能会成为问题。

这里是简单的macros来删除多张工作簿中的空白行。是这里问题的表是张数9。

Sub FnDeleteBlankRows() Dim mwb As WorkBook Set mwb = ActiveWorkBook For x = mwb.Sheets(“Sheet1”).Cells.SpecialCells(xlCellTypeLastCell).Row 1 Step –1 If WorksheetFunction.CountA(mwb.Sheets(“Sheet1”).Rows(x)) = 0 Then mwb.Sheets(“Sheet9”).Rows(x).Delete End If Next End Sub 

出现的错误是“用户定义types未定义”

之前我曾尝试下面的代码,并收到“语法错误”。 我尝试了谷歌search,并做了所有的标准修复(确保macros启用,devise器closures等,我甚至保存我的表格为xltm)

 Sub RemoveRows() Dim lastrow As Long Dim ISEmpty As Long Count how many records in the list. This is done so that the Do loop has a finish point. lastrow = Application.CountA(Range(“A:A”)) 'Start at the top of the list Range(“A1″).Select Loop until the end of the list Do While ActiveCell.Row < lastrow Assign number of non empty cells in the row ISEmpty = Application.CountA(ActiveCell.EntireRow) If ISEmpty = 0 then delete the row, if not move down a cell into the next row If ISEmpty = 0 Then ActiveCell.EntireRow.Delete Else ActiveCell.Offset(1, 0).Select End If LoopEnd Sub 

尽pipe我很喜欢学习VBA的更好的一点,但是我真的很想学习如何使用最小的定制开箱即可开发一个macros。

谢谢

试试这个,确保将Sheet1更改为正在处理的工作表。


testingExcel 2010

 Option Explicit '// Delete blank Rows Sub xlDeleteBlankRows() Dim xlWb As Workbook Dim i As Long Set xlWb = ActiveWorkbook For i = xlWb.Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).row To 1 Step -1 If WorksheetFunction.CountA(xlWb.Sheets("Sheet1").Rows(i)) = 0 Then xlWb.Sheets("Sheet1").Rows(i).Delete End If Next End Sub 

 Option Explicit Sub xlRemoveRows() Dim lastrow As Long Dim ISEmpty As Long '// Count how many records in the list. This is done so that the Do loop has a finish point. lastrow = Application.CountA(Range("A:A")) '// Start at the top of the list Range("A1").Select '// Loop until the end of the list Do While ActiveCell.Row < lastrow '// Assign number of non empty cells in the row ISEmpty = Application.CountA(ActiveCell.EntireRow) '// If ISEmpty = 0 then delete the row, if not move down a cell into the next row If ISEmpty = 0 Then ActiveCell.EntireRow.Delete Else ActiveCell.Offset(1, 0).Select End If Loop End Sub 

请参阅MSDN 入门Excel 2010和2013中有用的文章


 Option Explicit Sub xlDeleteRow() Dim lngRow, lngCrnt, lngCol As Long Dim xlBln As Boolean Application.ScreenUpdating = False lngRow = Cells(Rows.count, "A").End(xlUp).Row For lngCrnt = lngRow To 1 Step -1 xlBln = False For lngCol = 1 To 2 If Cells(lngCrnt, lngCol).Value <> vbNullString Then xlBln = True Exit For End If Next lngCol If Not xlBln Then Rows(lngCrnt).Delete Next lngCrnt Application.ScreenUpdating = True End Sub