VBA自动filter不按我的标准过滤

我创build了一个以前工作的filterfunction,但是我离开了它几天(在周末),它没有正确过滤。

我已经包含了下面的代码进行检查。 我已经运行了手表,并且一切似乎正确地进入自动filter行。 我正在用尽想法。

有没有什么我可能已经改变了自己破坏autofilter表单本身? 我能否在违规的标准之一中添加某些内容?

谢谢

注意:任何不是DIM的variables都是全局variables或垃圾variables。 而且,sortfield的索引可能是closures的; 我正在努力追踪。 它仍然似乎在正确的列中筛选时,它只是过滤掉所有的东西。

Private Sub Filter_CommandButton_Click() 'Filters by a text input and a column to filter Dim isInCol As Boolean Dim sortKey As String Dim sortOrder As XlSortOrder Dim currentData As Range Dim sortField As Integer ' This is the offset, determined by list index Dim lastRow As Integer ' used to set working range If filterColumn Is Nothing Then gojira = MsgBox("You need to enter a column to filter", vbOKOnly) Exit Sub End If ' Set target = ActiveWorkbook.Worksheets("Testing_Filter_Form") lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1 ' target.Cells(Rows.Count, "A").End(xlUp).Row + 1 ' put borders around whole row ' target.Range(target.Cells(lastRow, 1), target.Cells(lastRow, 56)).Borders.LineStyle = xlContinuous ' setting active sheet complete data Set currentData = ActiveSheet.Range(ActiveSheet.Cells(1, 1), ActiveSheet.Cells(lastRow, 12)) ' make sort key a wildcard If include = True Then sortKey = "*" & filterText & "*" Else ' for excluding the entered text sortKey = "<>" & "*" & filterText & "*" End If ' find list index for sorting sortField = Me.ColumnFilter_ComboBox.ListIndex ' + 1 ' populate sort order with value of Ascend/Descend options. If descend Then sortOrder = xlDescending Else sortOrder = xlAscending End If ' Search column to see if text exists isInCol = False For Each foo In filterColumn If caseSense Then If InStr(foo.Value, filterText) Then ' > 0 Then isInCol = True Exit For End If ElseIf Not caseSense Then If InStr(LCase(foo.Value), LCase(filterText)) Then isInCol = True Exit For End If End If Next foo If isInCol Then ' filter the table by the selected col; Use Range Sort With target currentData.AutoFilter Field:=sortField, Criteria1:=sortKey, VisibleDropDown:=False currentData.Sort key1:=filterColumn, Order1:=sortOrder, Header:=xlYes End With End If blah = bleh End Sub