删除特定数据下方的空白行

时间:2016-05-24 08:12:28

标签: excel vba

我需要一个脚本(Excel VBA),它会删除电子表格中空白 <星期一&#39;出现 - 有人可以帮忙吗?

在下面的示例中,我需要星期一在一起(没有空行)

name    Monday 02 05 16

name    Monday 02 05 16

name    Monday 02 05 16

name    Monday 02 05 16  
name    Tuesday 03 05 16  
name    Tuesday 03 05 16

1 个答案:

答案 0 :(得分:1)

试试这个

Option Explicit

Sub MAIN()
Dim cell As Range
Dim mondaysAddress As String

With Worksheets("MyWS") '<~~ replace "MyWS" with you actual worksheet name    
    For Each cell In .Columns("A").SpecialCells(xlCellTypeConstants, xlTextValues)'<~~ replace "A" with whatever column cells you must search the word "Monday" in
        If InStr(UCase(cell.Value), "MONDAY") Then
            If IsEmpty(cell.Offset(1)) Then mondaysAddress = mondaysAddress & cell.Offset(1).Address & ","
        End If
    Next cell
    mondaysAddress = Left(mondaysAddress, Len(mondaysAddress) - 1)
    Range(mondaysAddress).EntireRow.Delete
End With

End Sub