简体   繁体   English

使用VBA删除excel中的行

[英]Delete Rows in excel using VBA

I want to run a code that will go down all of column D (D:D) in my sheet named PxV and if they find a blank cell it will completely delete that corresponding row.我想运行一个代码,该代码将在我名为 PxV 的工作表中的所有列 D (D:D) 中向下移动,如果他们找到一个空白单元格,它将完全删除相应的行。 Another caveat is idk if my cells are truly blank?如果我的单元格真的是空白的,另一个警告是 idk? There is a formula running through all the cells and if it is false returns "".有一个公式贯穿所有单元格,如果它是假的,则返回“”。 Idk if this would be recognized as blank by VBA so if you would have to delete cells that have "" even though they're blank.如果这将被 VBA 识别为空白,那么如果您必须删除具有“”的单元格,即使它们是空白的。 It would also be nice to run continuously so when new data is populates it runs but I am not sure if that is possible .连续运行也很好,因此当填充新数据时它会运行,但我不确定这是否可能。 Thanks!!!谢谢!!!

See if this works.看看这是否有效。 You'll need to edit the code to match your sheet name and column.您需要编辑代码以匹配您的工作表名称和列。

Sub DelRow()
Dim ws As Worksheet
Dim SheetsToSearch, SrchStrg As String, r As Range
Set ws = Sheets("Sheet1")
SrchStrg = ""
SrchStrg2 = 0

Application.ScreenUpdating = False
    With ws.Range("A:A")
        Set r = .Find(what:=SrchStrg, After:=.Range("A1"))
        For Each r In ws.Range("A1:A1000")
            If r = SrchStrg Then
                r.EntireRow.Delete
            ElseIf r = SrchStrg2 Then
                r.EntireRow.Delete
            End If
        Next
    End With
Application.ScreenUpdating = True
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM