I use this same code multiple times throughout my workbook with different columns, but only having problems with this one and I don't know why. Any insight would be appreciated. The purpose is replace values in column AP that are less than 1 with the number "7". The 7 is then replaced with #N/A. The values in AP are then sorted in descending order so #N/A is at top. It is then supposed to filter and delete. My set range is G:AP.
As you can see from image, the values are being sorted properly, but they are not being removed.
VBA Code:
'''''''''''''''''''''''''''NO MVP UNDER 15 PROB AND 15 TARGET
lLastRowDeDuped = Cells(Rows.Count, lFirstWriteColumn).End(xlUp).Row
''Add MVP Column (column AP)
Cells(1, lLastWriteColumn + 31).Value = ChrW(931) & " MVP"
With Range(Cells(2, lLastWriteColumn + 31), Cells(lLastRowDeDuped, lLastWriteColumn + 31))
.Formula2R1C1 = "=COUNTIFS(RC[-15],"">15"",RC[-10],"">15"")"
Application.Calculate
.Value = .Value
End With
With Range("AP2", Range("AP" & Rows.Count).End(xlUp))
.Value = Evaluate(Replace("if(@<1,7,if(@="""","""",@))", "@", .Address))
End With
LR = Range("G" & Rows.Count).End(xlUp).Row
Set c = Intersect(ActiveSheet.UsedRange, Range("AP:AP"))
c.Replace What:="7", replacement:="#N/A", LookAt:=xlWhole
On Error Resume Next
ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Add2 Key:=Range( _
"AP2:AP400000"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Worksheet").Sort
.SetRange Range("G1:AP400000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("AP1").CurrentRegion.Select
With Selection
ActiveSheet.Range("$G$1:$AP$400000").AutoFilter Field:=36, Criteria1:="#N/A"
j = WorksheetFunction.Count(ActiveSheet.Range("$G$1:$AP$400000").Cells.SpecialCells(xlCellTypeVisible))
If j = 0 Then
ActiveSheet.AutoFilterMode = False
GoTo Continue_Code14
End If
.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
ActiveSheet.Range("$G$1:$AP$400000").AutoFilter Field:=36
Selection.AutoFilter
On Error GoTo 0
Continue_Code14:
End With
As you can see from image, the values are being sorted properly, but they are not being removed.