Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default excel vba - filters and ranges

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default excel vba - filters and ranges

So the issue is that you are inserting rows and moving your criteria range
every time you insert rows? I assume you are also having an issue in that the
paste area needs to be incremented as you insert rows? It is a little hard to
tell from your post...
--
HTH...

Jim Thomlinson


" wrote:

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default excel vba - filters and ranges

Yes. As I add another row the criteria range moves down another row but
macro does update the change . In additon the range used for the
filter....("A1:I4").AdvancedFilter does not capture the additonal row.
The paste area will also have to change.


Jim Thomlinson wrote:
So the issue is that you are inserting rows and moving your criteria range
every time you insert rows? I assume you are also having an issue in that the
paste area needs to be incremented as you insert rows? It is a little hard to
tell from your post...
--
HTH...

Jim Thomlinson


" wrote:

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default excel vba - filters and ranges

Give this code a try. You will need to add a named range for the criteria
range. select the entire Criteria Range (A7:C8) and In the drop down just
above Column A where it says A7 place your cursor and overwrite it to the
word Criteria. This code should then work for you... (Extract is a named
range created automatically for you on an advanced filter copy, so if you
select A10 you will see the word exctract in the cell reference aboce column
A)...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

P.S. Say hi to my sister Michelle Thomlinson for me. She works for Agrium
too... I am off to a meeting for a while. I will check back a little later to
see how things are going for you...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Yes. As I add another row the criteria range moves down another row but
macro does update the change . In additon the range used for the
filter....("A1:I4").AdvancedFilter does not capture the additonal row.
The paste area will also have to change.


Jim Thomlinson wrote:
So the issue is that you are inserting rows and moving your criteria range
every time you insert rows? I assume you are also having an issue in that the
paste area needs to be incremented as you insert rows? It is a little hard to
tell from your post...
--
HTH...

Jim Thomlinson


" wrote:

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default excel vba - filters and ranges

Thanks again. When i paste the code I get an error highlighted in red
for the following portion. Unfortunately, I am not able to resilve the
issue due to my inexperience

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))

Jim Thomlinson wrote:
Give this code a try. You will need to add a named range for the criteria
range. select the entire Criteria Range (A7:C8) and In the drop down just
above Column A where it says A7 place your cursor and overwrite it to the
word Criteria. This code should then work for you... (Extract is a named
range created automatically for you on an advanced filter copy, so if you
select A10 you will see the word exctract in the cell reference aboce column
A)...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

P.S. Say hi to my sister Michelle Thomlinson for me. She works for Agrium
too... I am off to a meeting for a while. I will check back a little later to
see how things are going for you...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Yes. As I add another row the criteria range moves down another row but
macro does update the change . In additon the range used for the
filter....("A1:I4").AdvancedFilter does not capture the additonal row.
The paste area will also have to change.


Jim Thomlinson wrote:
So the issue is that you are inserting rows and moving your criteria range
every time you insert rows? I assume you are also having an issue in that the
paste area needs to be incremented as you insert rows? It is a little hard to
tell from your post...
--
HTH...

Jim Thomlinson


" wrote:

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default excel vba - filters and ranges

Sorry the Window wrapped the text... It should all be on one line in your
code window... or use this...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"), _
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

PS... My sister is Michelle Nutting... you would think I would know her
married name...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Thanks again. When i paste the code I get an error highlighted in red
for the following portion. Unfortunately, I am not able to resilve the
issue due to my inexperience

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))

Jim Thomlinson wrote:
Give this code a try. You will need to add a named range for the criteria
range. select the entire Criteria Range (A7:C8) and In the drop down just
above Column A where it says A7 place your cursor and overwrite it to the
word Criteria. This code should then work for you... (Extract is a named
range created automatically for you on an advanced filter copy, so if you
select A10 you will see the word exctract in the cell reference aboce column
A)...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

P.S. Say hi to my sister Michelle Thomlinson for me. She works for Agrium
too... I am off to a meeting for a while. I will check back a little later to
see how things are going for you...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Yes. As I add another row the criteria range moves down another row but
macro does update the change . In additon the range used for the
filter....("A1:I4").AdvancedFilter does not capture the additonal row.
The paste area will also have to change.


Jim Thomlinson wrote:
So the issue is that you are inserting rows and moving your criteria range
every time you insert rows? I assume you are also having an issue in that the
paste area needs to be incremented as you insert rows? It is a little hard to
tell from your post...
--
HTH...

Jim Thomlinson


" wrote:

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default excel vba - filters and ranges

I have not met your sis - i am in Treasury but i will drop by. I named
the range but the code results in a "400 error" or a run time error
"1004 with application defined or object defined error" if I step
through it. Too bad you cannot attach files in the forum.

Jim Thomlinson wrote:
Sorry the Window wrapped the text... It should all be on one line in your
code window... or use this...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"), _
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

PS... My sister is Michelle Nutting... you would think I would know her
married name...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Thanks again. When i paste the code I get an error highlighted in red
for the following portion. Unfortunately, I am not able to resilve the
issue due to my inexperience

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))

Jim Thomlinson wrote:
Give this code a try. You will need to add a named range for the criteria
range. select the entire Criteria Range (A7:C8) and In the drop down just
above Column A where it says A7 place your cursor and overwrite it to the
word Criteria. This code should then work for you... (Extract is a named
range created automatically for you on an advanced filter copy, so if you
select A10 you will see the word exctract in the cell reference aboce column
A)...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

P.S. Say hi to my sister Michelle Thomlinson for me. She works for Agrium
too... I am off to a meeting for a while. I will check back a little later to
see how things are going for you...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Yes. As I add another row the criteria range moves down another row but
macro does update the change . In additon the range used for the
filter....("A1:I4").AdvancedFilter does not capture the additonal row.
The paste area will also have to change.


Jim Thomlinson wrote:
So the issue is that you are inserting rows and moving your criteria range
every time you insert rows? I assume you are also having an issue in that the
paste area needs to be incremented as you insert rows? It is a little hard to
tell from your post...
--
HTH...

Jim Thomlinson


" wrote:

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default excel vba - filters and ranges

I just e-mailed you a spreadsheet showing you what I have... It could be an
issue with the named ranges most likely... Let me know if you don't get it or
if you have any problems with it...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

I have not met your sis - i am in Treasury but i will drop by. I named
the range but the code results in a "400 error" or a run time error
"1004 with application defined or object defined error" if I step
through it. Too bad you cannot attach files in the forum.

Jim Thomlinson wrote:
Sorry the Window wrapped the text... It should all be on one line in your
code window... or use this...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"), _
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

PS... My sister is Michelle Nutting... you would think I would know her
married name...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Thanks again. When i paste the code I get an error highlighted in red
for the following portion. Unfortunately, I am not able to resilve the
issue due to my inexperience

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))

Jim Thomlinson wrote:
Give this code a try. You will need to add a named range for the criteria
range. select the entire Criteria Range (A7:C8) and In the drop down just
above Column A where it says A7 place your cursor and overwrite it to the
word Criteria. This code should then work for you... (Extract is a named
range created automatically for you on an advanced filter copy, so if you
select A10 you will see the word exctract in the cell reference aboce column
A)...

Sub Macro1()
Dim rngToFilter As Range

Set rngToFilter = Range(Range("A1"),
Range("A1").End(xlToRight).End(xlDown))
rngToFilter.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Criteria"), _
CopyToRange:=Range("Extract"), _
Unique:=False
End Sub

P.S. Say hi to my sister Michelle Thomlinson for me. She works for Agrium
too... I am off to a meeting for a while. I will check back a little later to
see how things are going for you...
--
HTH...

Jim Thomlinson


"dbuc283" wrote:

Yes. As I add another row the criteria range moves down another row but
macro does update the change . In additon the range used for the
filter....("A1:I4").AdvancedFilter does not capture the additonal row.
The paste area will also have to change.


Jim Thomlinson wrote:
So the issue is that you are inserting rows and moving your criteria range
every time you insert rows? I assume you are also having an issue in that the
paste area needs to be incremented as you insert rows? It is a little hard to
tell from your post...
--
HTH...

Jim Thomlinson


" wrote:

I have a list of transactions to which I add records daily. I want to
to filter and extract records to another location on the spreadsheet
based on user defined criteria. My problem is that the code initially
selects the correct range but range references for the filter do not
appear to change as records are not does the range for filter critieria
adjust to reflect the addition of records. Obviously I am new to VBA
but help would be appreciated.

File format
Date CP Notional Cur Type Rate
28-Jul-06 RBC 1,972,950 EUR SWAP 1.4360
28-Jul-06 BNS 1,500,000 USD FWD 1.1250


Filter Criteria
Date CP
28-Jul-06 RBC


Code
Sub Macro1()
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:I4").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _"A7:C8"), CopyToRange:=Range("A10"),
unique:=False
End Sub








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
Pivot Table filters, especially DATE filters chris Excel Worksheet Functions 0 August 27th 08 04:33 AM
protect cell ranges in spreadsheet and have data filters on prizm Excel Discussion (Misc queries) 0 September 5th 06 08:50 PM
protect cell ranges in spreadsheet and have data filters on prizm Excel Worksheet Functions 2 September 1st 06 11:12 PM
Filters, Subtotal & Intacted Results after the filters' Removal kasiopi Excel Discussion (Misc queries) 5 February 24th 06 12:18 PM
Filters and dynamic ranges RD Wirr Excel Programming 1 August 29th 05 02:33 PM


All times are GMT +1. The time now is 05:55 PM.

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

About Us

"It's about Microsoft Excel"