我要删除在特定范围内包含空单元格的所有行(A和B列)。我尝试了多种选择,我在这里找到了。
Columns("A:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
我也试过:
Lastrow = Range("A:Z").Find("*", , , , xlByRows, xlPrevious).Row
For i = Lastrow To 1 Step -1
If Application.CountA(Range(Cells(i, 1), Cells(i, 2))) = 0 Then Rows(i).Delete
Next i但是:这两个选项都找不到我的空单元格。我认为原因肯定是它们已经被粘贴到我的Excel表格中(仅限于PasteSpecial)。它们不包含值,但是是否仍然存在一些元数据来阻止它们被算法“找到”?两个宏都找不到空的单元格,基本上什么也不做。谢谢你的帮助。
发布于 2022-07-26 16:43:10
尝尝这个
For i = Lastrow To 1 Step -1
If trim(cells(i, 1))= "" or trim(cells(i, 2))= "" then cells(i, 1).entirerow.Delete
Next i发布于 2022-07-26 17:02:21
如果“邪恶”(160)存在.这样做:
Sub fnReplaceChar160AndDeleteBlankRows()
Selection.Replace What:="=Char(160)", Replacement:="", LookAt:=xlWhole _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
'now it's possible to delete the 'blank' rows
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End Subhttps://stackoverflow.com/questions/73126551
复制相似问题