VBA Autofilter 2003

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
How can I set an autofilter on a column, so that the filter takes not the empty "<>""" cells ?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,473
Record a macro where you Autofilter for Blanks or NonBlanks. Then look at the recorded macro to see the example code.
 
Upvote 0

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
Thanks JLGWiz, this is now my macro, but it does'nt work.
Any idea ?



Code:
Sub Filter()
Application.ScreenUpdating = False
  Sheets("Selectie").Cells.ClearContents
  With Sheets("XXXXXXX").UsedRange
          x = InputBox("Columnnumber")
         If Val(x) = 0 Then Exit Sub
         .Range("A4:R1000").Interior.ColorIndex = 0
         .AutoFilter x, "<>"
         .Copy Sheets("Bank").Cells(65536, 1).End(xlUp)
         .AutoFilter
         .Columns(1).Resize(, .Columns.Count).AutoFit
  End With
         Sheets("Bank").Columns(1).Resize(Sheets("Selectie").Columns.Count).AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
ADVERTISEMENT
Sorry JLGMiz, I was to fast with my answer. It really works fine
Million thanks
 
Upvote 0

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
Still an additional question about this Autofilter:

This filter works for column 15,16 and 17 (Autofilter x)

When 15 is choossen then after filtering : 16 and 17 delete
When 16 is choossen then after filtering : 15 and 17 delete
When 17 is choossen then after filtering : 15 and 16 delete

so at the end in the page "Bank", i have 1 column in place of 3
Is this possible ?
 
Upvote 0

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
ADVERTISEMENT
Still an additional question about this Autofilter:

This filter works for column 15,16 and 17 (Autofilter x)

When 15 is choossen then after filtering : 16 and 17 delete
When 16 is choossen then after filtering : 15 and 17 delete
When 17 is choossen then after filtering : 15 and 16 delete

so at the end in the page "Bank", i have 1 column in place of 3
Is this possible ?
This snippet would evealuate which column is being filtered and delete the other two. The remaining column will always appear as column O. If you use it outside the With statement, be sure to remove the periods in front of Columns and Range.
Code:
If x = 15 Then
    .Columns("P:Q").Delete
ElseIf x = 16 Then
    .Range("O1, Q1").EntireColumn.Delete
ElseIf x = 17 Then
    .Columns("O:P").Delete
End If
 
Upvote 0

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
Hello JLGWhiz,

Where to place your code in my macro (see nr.4)
Many thanks in advance.
 
Upvote 0

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Hello JLGWhiz,

Where to place your code in my macro (see nr.4)
Many thanks in advance.

Code:
Sub Filter()
Application.ScreenUpdating = False
    Sheets("Selectie").Cells.ClearContents
    With Sheets("XXXXXXX").UsedRange
        x = InputBox("Columnnumber")
        If val(x) = 0 Then Exit Sub
        .Range("A4:R1000").Interior.ColorIndex = 0
        .AutoFilter x, "<>"
        .Copy Sheets("Bank").Cells(65536, 1).End(xlUp)
        .AutoFilter
        .Columns(1).Resize(, .Columns.Count).AutoFit
        If x = 15 Then
            .Columns("P:Q").Delete
        ElseIf x = 16 Then
            .Range("O1, Q1").EntireColumn.Delete
        ElseIf x = 17 Then
            .Columns("O:P").Delete
        End If
    End With
    Sheets("Bank").Columns(1).Resize(Sheets("Selectie").Columns.Count).AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,195,934
Messages
6,012,386
Members
441,694
Latest member
Elvin A

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top