簡體   English   中英

VBA - 如果單元格為空,則刪除整行

[英]VBA - If cell blank, delete entire row

shMassPrelim.Range("AG2:AG" & lr).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

上面的代碼是我用來在列 AG 中查找空白單元格的代碼。 但是,列 AG 基於 If 公式。 這就是我返回“無單元格空白”錯誤的原因嗎?

嘗試這個?

Sub misc()
Dim cell As Range
Dim EMPTY_CELL As String
    EMPTY_CELL = ""
    For Each cell In Selection
        If Trim(cell.Value) = EMPTY_CELL Then
            cell.EntireRow.Delete
        End If
    Next
End Sub

這將過濾並刪除空白行

Sub DeleteStuff()
    Dim Rws As Long, Rng As Range

    Rws = Cells(Rows.Count, "AG").End(xlUp).Row
    Set Rng = Range(Cells(2, "AG"), Cells(Rws, "AG"))

    Application.ScreenUpdating = 0

    Range("AG:AG").AutoFilter Field:=1, Criteria1:="="
    Rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete

    ActiveSheet.AutoFilterMode = 0

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM