简体   繁体   English

删除包含数据的行

[英]Delete Rows containing Data

I have the following code and need to delete the rows of data in Column A that contain information. 我有以下代码,需要删除A列中包含信息的数据行。 These rows are "header" and "footer" information that skews access to the data that I need. 这些行是“页眉”和“页脚”信息,它们使对我所需数据的访问产生了歪斜。

I thought I had a solution setup as follows, but it doesn't seem to work to delete the correct rows in Column A. 我以为我有如下解决方案设置,但删除A列中的正确行似乎不起作用。

Code: 码:

Sub CleanUpFB()
    Dim Sheet4 As Worksheet
    Dim delRng As Range
    Dim LastRow As Integer, LastRow2 As Integer
    Dim i As Integer

    Set Sheet4 = Excel.Worksheets("FB Product")
    LastRow = Range("D3").End(xlDown).Row

    'Re-align Revision Column.
    Range("D3:D" & LastRow).Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.Delete Shift:=xlToLeft

    'Delete First Row
    Sheet4.Rows(1).Delete

    'Delete Rows in Column A that contain words.
    LastRow2 = Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To LastRow2
        If InStr(1, Cells(i, 1).Value, "*", vbTextCompare) Then
            If delRng Is Nothing Then
                Set delRng = Rows(i)
            Else
                Set delRng = Union(delRng, Rows(i))
            End If
        End If
    Next i

    If Not delRng Is Nothing Then delRng.Delete
End Sub

Worksheet: 工作表: 在此处输入图片说明

如果要删除整行中Col A中任何单元格都具有值的行:

Columns("A:A").SpecialCells(xlCellTypeConstants, 23).EntireRow.Delete

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

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