PC Review


Reply
Thread Tools Rate Thread

Autofilter for fixed columns

 
 
choo
Guest
Posts: n/a
 
      8th Mar 2010
Hi,
I have a big table from column A to BP, though the number of column is not
fixed. Sometimes it has additonal one or 2 extra columns append at the back,
so it could reach until column BR.

Regardless of how many columns I have in this table, I want to have a macro
that could turn on autofilter, filter column J for a value e.g. "John, C",
and then filter column AC and R for non-blank cells.

I tried the following, but it doesn't work.

..Columns("J:J").AutoFilter field:=1, Criteria1:="John, C"
..Columns("AC:AC").AutoFilter field:=1, Criteria1:="<>"
..Columns("R:R").AutoFilter field:=1, Criteria1:="<>"

Can anyone help?

choo
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      8th Mar 2010
I like to be specific with the range I'm filtering.

In most cases, I can pick out a column that always has data in it -- and that
can define the last row to include in the filtered range.

And I can usually pick out a row that can be used to determine last column to
use.

In this case, I used column A and row 1 to find the extent of the range to
filter.

And I wanted to start the filter in A1.

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim LastCol As Long
Dim LastRow As Long
Dim myRng As Range

Set wks = Worksheets("Sheet1")

With wks
.AutoFilterMode = False 'remove any existing filter
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

If LastCol < .Range("ac1").Column Then
MsgBox "not enough data!"
Exit Sub
End If

Set myRng = .Range("A1", .Cells(LastRow, LastCol))

myRng.AutoFilter field:=.Range("j1").Column, Criteria1:="John, C"
myRng.AutoFilter field:=.Range("ac1").Column, Criteria1:="<>"
myRng.AutoFilter field:=.Range("r1").Column, Criteria1:="<>"

End With

End Sub



choo wrote:
>
> Hi,
> I have a big table from column A to BP, though the number of column is not
> fixed. Sometimes it has additonal one or 2 extra columns append at the back,
> so it could reach until column BR.
>
> Regardless of how many columns I have in this table, I want to have a macro
> that could turn on autofilter, filter column J for a value e.g. "John, C",
> and then filter column AC and R for non-blank cells.
>
> I tried the following, but it doesn't work.
>
> .Columns("J:J").AutoFilter field:=1, Criteria1:="John, C"
> .Columns("AC:AC").AutoFilter field:=1, Criteria1:="<>"
> .Columns("R:R").AutoFilter field:=1, Criteria1:="<>"
>
> Can anyone help?
>
> choo


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula to stay fixed on two columns as you add more columns usingexcel Microsoft Excel Misc 1 3rd Aug 2006 01:25 AM
Which columns AutoFilter is on. brittonsm@gmail.com Microsoft Excel Programming 1 21st Jun 2006 03:26 AM
Which columns AutoFilter is on. brittonsm@gmail.com Microsoft Excel Programming 0 20th Jun 2006 11:50 PM
Which columns AutoFilter is on. brittonsm@gmail.com Microsoft Excel Programming 0 20th Jun 2006 11:50 PM
VBA to set which columns in Autofilter miker1999 Microsoft Excel Programming 2 15th Feb 2004 02:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:17 AM.