View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
crmulle crmulle is offline
external usenet poster
 
Posts: 11
Default Selection.AutoFilter Issue

I have the same code for 5 different reports. The only difference in code is
the criteria filtered and removed. All reports filter and remove the desired
data just fine except for one. The code is below and it is the same each
reports with the exception of the worksheets it is deleting and Criteria1 for
each sheet. NOTE: The BCP E&M code below filters correctly but not the
others...and they are the same code! Any help would be greatly appreciated.


Dim myLastRow As Long
Dim myLastColumn As Long
Dim myLastCell As String
Dim myRange As String
Dim Newbook As String
Dim fName As Variant
Dim MyDate As Date

Application.ScreenUpdating = False

MyDate = Date

Application.DisplayAlerts = False
Worksheets(Array("SUMMARY", "HCFG", "TOGCSG", "WBR")).Select
ActiveWindow.SelectedSheets.Delete

Sheets("New Vendors").Select

Worksheets("New Vendors").AutoFilterMode = False

Selection.AutoFilter Field:=4, _
Criteria1:="<WHOLESALE BANKING"

myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
xlPrevious).Column
myLastCell = Cells(myLastRow, myLastColumn).Address

If myLastCell = "" Or myLastRow = "1" Then
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

Else

myRange = "D2:" & "D" & myLastRow
Range(myRange).Delete
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

End If

Sheets("Pending").Select

Worksheets("Pending").AutoFilterMode = False

Selection.AutoFilter Field:=4, _
Criteria1:="<WHOLESALE BANKING"

myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
xlPrevious).Column
myLastCell = Cells(myLastRow, myLastColumn).Address

If myLastCell = "" Or myLastRow = "1" Then
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

Else

myRange = "D2:" & "D" & myLastRow
Range(myRange).Delete
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

End If

Sheets("BCP").Select

Worksheets("BCP").AutoFilterMode = False

Selection.AutoFilter Field:=4, _
Criteria1:="<WHOLESALE BANKING"

myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
xlPrevious).Column
myLastCell = Cells(myLastRow, myLastColumn).Address

If myLastCell = "" Or myLastRow = "1" Then
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

Else

myRange = "D2:" & "D" & myLastRow
Range(myRange).Delete
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

End If

Sheets("BCP E&M").Select

Worksheets("BCP E&M").AutoFilterMode = False

Selection.AutoFilter Field:=4, _
Criteria1:="<WHOLESALE BANKING"

myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myLastColumn = Cells.Find("*", [A1], , , xlByColumns,
xlPrevious).Column
myLastCell = Cells(myLastRow, myLastColumn).Address

If myLastCell = "" Or myLastRow = "1" Then
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

Else

myRange = "D2:" & "D" & myLastRow
Range(myRange).Delete
Selection.AutoFilter
Selection.AutoFilter
Range("A2").Select

End If