VBA autofilter gets wrong results

48 Views Asked by At

i've made a macro that inputs a vlookup formula on a column, then it filters only the #N/D results. This workbook is used by 4 different users on their own computers. On 3 computers it works, but on the 4th it filters the #N/D but doesn't "show" the results. I don't have any clue of what's going on, can you help?

The code:

Application.ScreenUpdating = False

Dim wb As Workbook, wb2 As Workbook
Dim lastRowWithData
Set wb = ActiveWorkbook
Set wb2 = Workbooks.Open("\\server\path\file.xlsx")
wb2.Activate
Application.CutCopyMode = False
wb2.Sheets("NFe").Select
Range("X1").Value = "Procv"
wb2.Sheets("NFe").Range("X2").Select
ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(RC[-21]&RC[-19],'\\server\path\[file2.xlsm]SheetName'!C2,1,0)"
lastRowWithData = GetLastRowWithData
wb2.Sheets("NFe").Range("X2").Select
Selection.AutoFill Destination:=Range("X2:X" & lastRowWithData)
wb2.Sheets("NFe").Range("X1").Select
Selection.AutoFilter Field:=24, Criteria1:="#N/D"

This is what the 4th computer shows (debug mode of Selection.AutoFilter Field:=24, Criteria1:="#N/D"): excel worksheet showing no records but the filter is right

When I do the same on my computer, or when I manually open the filter as the image above, and click on "ok" then it shows the results correctly: Excel worksheet showing 434 records with the #N/D result of vlookup

0

There are 0 best solutions below