1
我是新来的宏,但我怀疑其他可能在这里问题。运行一个简单的空白行遇到问题删除
这里是简单的宏在多片删除空白行workbook.Yes这里的片在的问题是张数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
其中出现的错误是“用户定义的类型不定义为“
早些时候,我曾尝试下面的代码,并收到”语法错误“。我试着用搜索引擎,做了所有标准的修订(确保宏被启用,设计师关闭等等,我甚至救了我板作为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
虽然我会享受学习VBA的细节问题我会真的很想学习如何使用最少的定制开箱即可开发宏。
谢谢
非常感谢奥马尔。第一个在For Looop上有一个运行时错误,但第二个完美地工作。对此,我真的非常感激。 请您指出我发布的两套代码的问题吗? – ResponsiveConsilience
第一个''.Row 1 Step -1'应该是'.row到1 Step -1'的语法错误,而且你所缺少的Dim i As Long代码没有写好代码,现在在第一个确保你改变了所有的sheet1名称因为它在我的电脑上运行正常。 – 0m3r
非常感谢奥马尔。其实第二个完美地运行,但空行不被删除:(我不知道它是否因为我使用Excel 2013 – ResponsiveConsilience