Excel Help with Autofilter and "Field: nn" from Mr Excel


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Help with Autofilter and "Field: nn"
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

jtma67
Welcome to the Board


Joined: 29 Dec 2003
Posts: 1

Flag: Blank

Status: Offline

 Reply with quote  

Help with Autofilter and "Field: nn"

I have a worksheet that I am using a macro with multiple Autofilter statements to select specific criteria as I create a summary report. One such statement I am using in the macro is:

code:
Selection.AutoFilter field:=31, Criteria1:="Y", Operator:=xlOr, Criteria2:="N"



My problem is if I add columns anywhere prior to column 31, my macro will return incorrect results...unless of course I appropriately update the "field: =nn" number to correct the offset.

Is there anyway to that I can modify the "field:=" parameter to make it update automatically?

I read an article that discussed a similar situation with VLOOKUP where the column index reference could automatically update.... that code looked like:

code:
=VLOOKUP(C1,A1:B12,COLUMN(B)-COLUMN(A1)+1)



However I couldn't get the COLUMN function to work. Thanks for any help.

Post Mon Dec 29, 2003 5:30 am 
 View user's profile Send private message

masim
Board Regular


Joined: 19 Jun 2003
Posts: 56
Location: Pakistan
Flag: Pakistan

Status: Offline

 Reply with quote  

Re: Help with Autofilter and "Field: nn"

hi

i was once trapped in a similar situation and i tried something like this.

assumption: row one contains headings.


Sub Button1_Click()

Dim col As Integer

Rows(1).Select
Selection.Find(What:="your Header name of column 31", LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

col = ActiveCell.Column

Selection.AutoFilter Field:=col, Criteria1:="Y", Operator:=xlOr, Criteria2:="N"

End Sub

you may need to modilfy the code to suit your needs but the idea i used was to search for the header name and get the column number returned and then apply the filter on the column number.

Regards
Asim

Post Mon Dec 29, 2003 8:08 am 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.