Question

I have the following code and need to delete the rows of data in Column A that contain information. 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.

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: enter image description here

Was it helpful?

Solution

If you want to delete the whole row where any cell in Col A has a value:

Columns("A:A").SpecialCells(xlCellTypeConstants, 23).EntireRow.Delete
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top