根据列中的空白单元格删除整行

时间:2019-07-09 14:43:37

标签: excel vba sharepoint-2010

我们正在使用SharePoint导出的Excel文件来跟踪加班。有两个方面会影响我遇到的这个问题:

  1. 员工通过在“ P”列中输入“开始时间”来显示他们的工作
  2. 如果计划了加班时间,但员工没有处理OT,他们会将单元格留在“ P”空白列中。

这甚至可能是设置错误。我在PERSONAL.xlsb VBAProject中添加了一个模块。

然后,我尝试了一堆在这里找到的代码,以搜索类似的案例,但似乎无济于事。

我正在使用Excel 2016。

我尝试了很多代码,但这似乎是最简单的:

Sub NewBlanks()
    Dim LastRow As Integer
    LastRow = Range("A" & Rows.Count).End(xlUp).row
    Range("P2:P" & LastRow).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

我只希望宏查看'P'列,如果单元格为空白,则删除整行,向上移动行以填补该空白。

1 个答案:

答案 0 :(得分:0)

尝试一下:

Sub DeleteRows()
Dim mFind As Range

Set mFind = Columns("P").Find("")
If mFind Is Nothing Then
    MsgBox "There is no cell found with the text ''" _
    & " in column P of the active sheet."
    Exit Sub
End If

firstaddress = mFind.Address

Do

    Range(mFind, Cells(mFind.Row, "P")).EntireRow.Delete
    Set mFind = Columns("P").Find("")
    If mFind Is Nothing Then Exit Sub
    Set mFind = Columns("P").FindNext(mFind)

Loop While mFind.Address <> firstaddress

End Sub

最亲切的问候

相关问题