It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Using Defined Name when Filtering

Moderator: dafunkymunky

Using Defined Name when Filtering

Postby HTL on Mon Feb 15, 2010 3:50 pm

-I am wanting to control the filter on a block of data via VB
-I want to use a defined name instead of stating what the filter should be set to
- My defined name points to a cell that is linked to a drop down box (so when the drop down is changed the name in the defined name cell changes and thus resets the filters).

So I could write:

Sub Test_Filter()

Name1 = ActiveWorkbook.Sheets("Look Ups").Range("I139").Value

If Name1 = "Bebo" Then ActiveWorkbook.Sheets("Graph Data - All").Range("$A$58:$D$3052").AutoFilter Field:=3, Criteria1:= _
"Bebo"

Else If = "Facebook" Then ActiveWorkbook.Sheets("Graph Data - All").Range("$A$58:$D$3052").AutoFilter Field:=3, Criteria1:= _
"Facebook"
End Sub

But what I really want to do is:

Sub Test_Filter()

Name1 = ActiveWorkbook.Sheets("Look Ups").Range("I139").Value

ActiveWorkbook.Sheets("Graph Data - All").Range("$A$58:$D$3052").AutoFilter Field:=3, Criteria1:= _
"Name1"

End Sub

The reason for this is that this is a monthly report and the variables I want to filter by will change every month and I don't want to have to go back into the code each month and re-enter all the sites.

Any suggestion would be much appreciated.
HTL
 
Posts: 1
Joined: Mon Feb 15, 2010 3:30 pm

Who is online

Users browsing this forum: No registered users and 4 guests