Hi shauncol3,
As long as the data starts in row 2, try the following (though initially on a copy of your data as the results cannot be undone if they're not as expected):
Option Explicit
Sub Macro1()
'Written by Trebor76
'Visit my website www.excelguru.net.au
Dim lngMyCol As Long, _
lngMyRow As Long
Dim strMyCol As String
Dim xlnCalcMethod As XlCalculation
lngMyCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
lngMyRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
strMyCol = Left(Cells(1, lngMyCol).Address(True, False), Application.WorksheetFunction.Search("$", Cells(1, lngMyCol).Address(True, False)) - 1)
With Application
xlnCalcMethod = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With Columns(lngMyCol)
With Range(Cells(2, lngMyCol), Cells(lngMyRow, lngMyCol))
.Formula = "=IF(AA2=1,""DEL"",IF(AA2=2,"""",IF(" & strMyCol & 1 & "=""DEL"",""DEL"","""")))"
ActiveSheet.Calculate
.Value = .Value
End With
.Replace "DEL", "#N/A", xlWhole
On Error Resume Next 'Turn error reporting off - OK to ignore 'No cells found' message
.SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
On Error GoTo 0 'Turn error reporting back on
.Delete
End With
With Application
.Calculation = xlnCalcMethod
.ScreenUpdating = True
End With
End Sub
Regards,
Robert
Bookmarks