Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Advanced Filter VB Script for Variable Criteria Range

I'm new to scripting within Excel, and I am wondering if it is possible to
write a script for an Advanced Filter where the Criteria Range is itself a
variable. I would like to filter the data in a spreadsheet with the data in
a single column of another sheet. Since the amount of data in this column
can change from time to time and selecting the entire column incudling blank
cells below the data doesn't work, I want to have the filter adjust
accordingly. Example script:

Range (.Cells). AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets ("Sheet1") .Range(VARIABLE RANGE HERE), Unique:=False

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Advanced Filter VB Script for Variable Criteria Range

Hi Jason

You can use a dynamic range name
http://www.contextures.com/xlNames01.html#Dynamic

--
Regards Ron De Bruin
http://www.rondebruin.nl



"Jason" wrote in message ...
I'm new to scripting within Excel, and I am wondering if it is possible to
write a script for an Advanced Filter where the Criteria Range is itself a
variable. I would like to filter the data in a spreadsheet with the data in
a single column of another sheet. Since the amount of data in this column
can change from time to time and selecting the entire column incudling blank
cells below the data doesn't work, I want to have the filter adjust
accordingly. Example script:

Range (.Cells). AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets ("Sheet1") .Range(VARIABLE RANGE HERE), Unique:=False

Thanks!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Advanced Filter VB Script for Variable Criteria Range

Hi Jason,

You may try to use the code below.

Different rg value will do different Filter and get different result.

Sub Macro1()
Dim rg As Range
'Set rg = Sheets("Sheet1").Range("C1:C2")
Set rg = Sheets("Sheet1").Range("D1:D2")
Range("A1:A16").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
rg, Unique:=False
End Sub


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced Filter - Criteria Range issue Tina Excel Discussion (Misc queries) 4 June 11th 09 03:28 PM
Advanced Filter using a range name as the criteria Joe Excel Worksheet Functions 1 December 27th 08 06:23 PM
Building criteria string for Advanced Filter variable not resolvin JEFFWI Excel Discussion (Misc queries) 1 August 29th 07 07:52 PM
Advanced filter and Criteria Range gearoid Excel Discussion (Misc queries) 2 July 20th 05 02:33 PM
"Criteria Range" in the "Data/Filter/Advanced Filter" to select Du TC Excel Worksheet Functions 1 May 12th 05 02:06 AM


All times are GMT +1. The time now is 01:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"