![](/img/trans.png)
[英]How do I copy and paste cells and then delete certain rows in a specific way using excel VBA?
[英]How can I delete empty cells in Excel using VBA after a Copy/Paste?
我想刪除包含特定范圍內的空單元格的所有行(A 列和 B 列)。 我嘗試了多個選項,我在 SO 上找到了這些選項。
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
但是:這兩個選項都找不到我的空單元格。 我認為原因一定是它們已被粘貼(僅限PasteSpecial-Values)到我的 Excel 表中。 它們不包含任何值,但是否仍有一些元數據阻止它們被算法“找到”? 這兩個宏都沒有找到任何空單元格,基本上什么都不做。 謝謝您的幫助。
嘗試這個
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
如果 'evil' char(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 Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.