错误400当做.SpecialCells(xlCellTypeBlanks).EntireRow.Delete

我坚持我的代码的这部分,只是不能通过它:

'Sort Active Sheet By Property Case Number Sheet2.Range("A1:AQ" & Sheet2.UsedRange.Rows.Count).Sort Key1:=Sheet2.Range("Z1"), Order1:=xlAscending, Header:=xlYes 'Remove Duplicate Property Case Number Sheet2.Range("A1:AQ" & Sheet2.UsedRange.Rows.Count).RemoveDuplicates Columns:=26, Header:=xlYes 'Add Formula To Detect blank rows. This is a fix for the mistery blank rows that appear at this point If Sheet2.UsedRange.Rows.Count > 1 Then Sheet2.Range("AR1").Value = "Temp" Sheet2.Range("AR2").Formula = "=IF(COUNTA(A2:AQ2)<>0,""Not Empty"","""")" '"=IF(COUNTA(A2:AQ2)=0,""Not Empty"","""")" Sheet2.Range("AR2").AutoFill Destination:=Sheet2.Range("AR2:AR" & Sheet2.UsedRange.Rows.Count), Type:=xlFillSeries Sheet2.Columns("AR").Copy Sheet2.Columns("AR").PasteSpecial Paste:=xlPasteValues Sheet2.Range("A1:AR" & Sheet2.UsedRange.Rows.Count).Sort Key1:=Sheet2.Range("AR1"), Order1:=xlAscending, Header:=xlYes Sheet2.Columns("AR").SpecialCells(xlCellTypeBlanks).EntireRow.Delete Sheet2.Columns("AR:AR").Delete End If 

这里的问题是当代码执行“ .RemoveDuplicates Columns:= 26,Header:= xlYes ”时,它将删除重复的行,但是这些行仍然包含在sheet1.usedrange.rows.count中 ,就像它们具有不可见的内容或其他内容一样。

所以现在我不得不添加一个代码来删除那些不可见的行,并将它们从usedrange数中排除。 我试图做一个“ .SpecialCells(xlCellTypeBlanks).EntireRow.Delete ”,但我一直得到一个错误400,我不能看到我的代码有任何问题,我得到这个错误。 顺便说一下,我是那种喜欢不使用循环代码来逐个检查行的程序员,我想要创build一个尽可能快的程序。