Hi all!
I have a macro which sets auto filters, but it is not working in one case and I am not able to understand why. Here is the part which is not working.
If there is any cell with "X" in column U and any cell in column O is not empty (there are formulas in column O, but result of formula is ""), then apply filters. Else show message box.
Now if there is no "X" in column U it works fine, it shows msg box. But if there is "X" and all cells in column O are blank (only formulas) it still applies the filters, but it should show message box instead. Any idea how to fix it?
I have a macro which sets auto filters, but it is not working in one case and I am not able to understand why. Here is the part which is not working.
If there is any cell with "X" in column U and any cell in column O is not empty (there are formulas in column O, but result of formula is ""), then apply filters. Else show message box.
Now if there is no "X" in column U it works fine, it shows msg box. But if there is "X" and all cells in column O are blank (only formulas) it still applies the filters, but it should show message box instead. Any idea how to fix it?
VBA Code:
Sub PricingTransferMPG()
Dim lngLastRow As Long
With ActiveSheet
lngLastRow = .range("A" & .Rows.Count).End(xlUp).Row
With .range("$A$3:$BB" & lngLastRow)
'THIS LINE IS NOT WORKING
If WorksheetFunction.CountIf(range("U3:U" & lngLastRow), "X") > 0 And WorksheetFunction.CountIf(range("O3:O" & lngLastRow), "<>") > 0 Then
.AutoFilter Field:=21, Criteria1:="X"
.AutoFilter Field:=15, Criteria1:="<>"
.AutoFilter Field:=17, Criteria1:="1"
Worksheets("SUM").range("AX3:BA" & lngLastRow).Copy
Worksheets("LSMW ZVOL MAT PR GRP").range("A4").PasteSpecial xlPasteValues
Else
MsgBox "No MPG condition exist.", vbInformation, "No data"