This is is Excel 2010 on Windows 7.
I receive spreadsheets where one of the columns is called "Approved." This column is filled with x's and blanks. I want to delete all rows that have blanks in that column. This is a simple problem but has two confounding issues:
- The location of the Approved column changes, so I can't just do Columns("R").SpecialCells(xlBlanks).EntireRow.Delete. I try to get around this by searching for "Approve" in A1:Z5 (since there are always fewer than 26 rows), and selecting the column in which it is found.
- Much of the data is pulled from a previous month's document so some of the "blank" cells are populated with a vlookup. I try to get around this by first selecting all data and pasting as values.
Here is the current code:
Sub DeleteCol()
Range("A1").Select
Range(Selection, Selection.SpecialCells(xlLastCell)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim rngApprove As Range
Set rngApprove = Range("A1:Z5").Find("Approve")
If rngApprove Is Nothing Then
MsgBox "Approved column was not found."
Exit Sub
End If
Dim approved_column As Range
Set approved_column = rngApprove.EntireColumn
approved_column.SpecialCells(xlBlanks).EntireRow.Delete
End Sub
The copy + paste as value works as intended. However, the row deletion only deletes rows 1-4 and leaves everything below row 5 alone, even though some of those cells are blank. If I replace the last line with
approved_column.select
it selects the whole column, as it should. This leads me to believe that the issue is with my deletion method.