Solved

Reference by column name instead of an absolute number

Posted on 2013-12-05
2
328 Views
Last Modified: 2013-12-24
Hi, I have a working macro that performs the following:
1. Selects all the fields in a table in the column "Functional Area" besides the  function  that was selected on the cover sheet (aka. Series_Name);
2. Deletes all those fields and their data in the table;
3. Then un-filters (shows) only the selected function

It is running fine when I refer to the column number of Initiative Summary tab (number 3). However, when I'm trying  to reference by name instead of referring to absolute column numbers, the macro doesn't work.
o      Instead of:
¿      Sheets("Initiative Summary").ListObjects("InitiativeTbl").Range.AutoFilter Field:=3
o      I try:
¿      Sheets("Initiative Summary").ListObjects("InitiativeTbl").Range.AutoFilter Field:=.ListColumns("Functional Area").Index

Could you please help me figure out how to make it work?

Sub Macro3()
'
' Macro3 Macro
'
Dim Series_Name As String

   Series_Name = Range("Cover!$C$8").Value
   
  If Series_Name <> "All" Then
   
     Sheets("Initiative Summary").ListObjects("InitiativeTbl").Range.AutoFilter Field:=3
   
     With Sheets("Initiative Summary").ListObjects("InitiativeTbl")
   
        .Range.AutoFilter Field:=.ListColumns("Functional Area").Index, Criteria1:=("<>" & Series_Name), Operator:=xlFilterValues
   
     End With
   
     Sheets("Initiative Summary").ListObjects("InitiativeTbl").ListColumns("Functional Area").DataBodyRange.SpecialCells(xlCellTypeVisible).Delete
   
     With Sheets("Initiative Summary").ListObjects("InitiativeTbl")
        .Range.AutoFilter Field:=3
     End With
     
   Else
      Sheets("Initiative Summary").ListObjects("InitiativeTbl").Range.AutoFilter Field:=3

End If

End Sub
0
Comment
Question by:jmac001
2 Comments
 
LVL 4

Expert Comment

by:andrew_man
ID: 39699023
Post the file here, okay?
0
 
LVL 33

Accepted Solution

by:
Rob Henson earned 500 total points
ID: 39700495
Does the user have to select the column name in some way?

If so, create a variable from that selection and use that variable in a MATCH function to generate the column number:

Application.WorksheetFunction.Match(Variable,Range,MatchType)

Thanks
Rob H
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question