【问题标题】:Deleting entire row based on blank cell in column根据列中的空白单元格删除整行
【发布时间】:2019-07-10 02:04:02
【问题描述】:

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

  1. 员工通过在“P”列中输入开始时间来显示他们的工作
  2. 如果计划加班但员工没有加班,他们会将“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”列,如果单元格为空白,则删除整行,向上移动行以填补空白。

【问题讨论】:

  • Dim LastRow as Long 而不是 As Integer。您是否遇到任何错误?
  • 使用自动过滤器,如下所示delete row based on condition
  • @BigBen 我收到错误:Range 类的删除方法失败
  • @SiddharthRout 使用链接页面中的代码...我如何修改它以在 P 列中查找空白而不是“FemImplant$”术语?谢谢。

标签: excel vba sharepoint-2010


【解决方案1】:

试试这个:

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

最诚挚的问候

【讨论】:

  • 谢谢。这段代码给了我一个“编译错误:变量未定义”它突出显示:firstaddress =
  • @jeremy 然后在子目录的顶部声明它
  • 我不知道该怎么做。
  • Dim firstaddress As String
猜你喜欢
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
  • 2018-04-14
  • 1970-01-01
  • 1970-01-01
  • 2019-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多