PC Review


Reply
Thread Tools Rate Thread

Autofilter and VBA

 
 
haas786@yahoo.com
Guest
Posts: n/a
 
      9th Oct 2007
Hey all,

I was wondering if you could help me with a VBA problem. I need to
program a macro which would essentially Autofilter a large amount of
information based on two criteria. The critera is listed in two cells
(in cells on another tab/worksheet named "Claims" - cells G2 and G3.)
The values in these cells match entries in two of the columns being
filtered.

So, for example, cell G2 in worksheet "Claims" = "Auto" and cell G3 =
"NJ" - I need the program to filter the data in my other worksheet
("Data") by the two cvalues listed above. Once I get the filter to
work, I need to copy all this data and paste it into a new workbook.

I hope i explained the above well enough to allow you to help me. If
you have any further questions, please ask. Thank you in advance.

-Haas

 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      9th Oct 2007
You didn't say which columns to filter the data sheet on, so I used D
and F (4 and 6). To do different columns, just change the Field
property of the AutoFilter.
Sub tryThis()
Dim ws As Worksheet
With Sheets("Data")
.AutoFilterMode = False
.Cells.AutoFilter Field:=4, _
Criteria1:=Sheets("Claims").Range("G2").Text
.Cells.AutoFilter Field:=6, _
Criteria1:=Sheets("Claims").Range("G3").Text
Set ws = Worksheets.Add(Before:=Sheets("Data"))
.UsedRange.Copy ws.Range("A1")
.AutoFilterMode = False
End With
Set ws = Nothing
End Sub

(E-Mail Removed) wrote:
> Hey all,
>
> I was wondering if you could help me with a VBA problem. I need to
> program a macro which would essentially Autofilter a large amount of
> information based on two criteria. The critera is listed in two cells
> (in cells on another tab/worksheet named "Claims" - cells G2 and G3.)
> The values in these cells match entries in two of the columns being
> filtered.
>
> So, for example, cell G2 in worksheet "Claims" = "Auto" and cell G3 =
> "NJ" - I need the program to filter the data in my other worksheet
> ("Data") by the two cvalues listed above. Once I get the filter to
> work, I need to copy all this data and paste it into a new workbook.
>
> I hope i explained the above well enough to allow you to help me. If
> you have any further questions, please ask. Thank you in advance.
>
> -Haas


 
Reply With Quote
 
Bill Renaud
Guest
Posts: n/a
 
      10th Oct 2007
JW,

Won't this copy the ENTIRE worksheet? The OP only wanted the filtered data
to be copied? You used the line:

.UsedRange.Copy ws.Range("A1")

--
Regards,
Bill Renaud



 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      11th Oct 2007
On Oct 10, 3:01 am, "Bill Renaud" <Bill.No.Spam.Ren...@Comcast.Net>
wrote:
> JW,
>
> Won't this copy the ENTIRE worksheet? The OP only wanted the filtered data
> to be copied? You used the line:
>
> .UsedRange.Copy ws.Range("A1")
>
> --
> Regards,
> Bill Renaud


Bill, actually no. It will only copy the filtered data. It's one of
those crazy Excel things where it seems like one bit of code would
cause one thing to happen, but it actually works for some reason.
Give it a go and let me know if it works for you.

Regards
-Jeff-

 
Reply With Quote
 
Bill Renaud
Guest
Posts: n/a
 
      11th Oct 2007
Yep, it works in Excel 2000 (SP-3) (copying filtered data)!

I am VERY skeptical of this "feature" (bug?), though. This behavior is not
documented in either the UsedRange property or the Copy method! The caveat
is that it only works if the rows were hidden by using AutoFilter. If the
rows were hidden using the normal Format|Row|Hide command, then ALL of the
data is copied, as I first mentioned. This is true, even though AutoFilter
essentially works by simply hiding the rows not wanted!

--
Regards,
Bill Renaud



 
Reply With Quote
 
haas786@yahoo.com
Guest
Posts: n/a
 
      11th Oct 2007
On Oct 11, 2:01 am, "Bill Renaud" <Bill.No.Spam.Ren...@Comcast.Net>
wrote:
> Yep, it works in Excel 2000 (SP-3) (copying filtered data)!
>
> I am VERY skeptical of this "feature" (bug?), though. This behavior is not
> documented in either the UsedRange property or the Copy method! The caveat
> is that it only works if the rows were hidden by using AutoFilter. If the
> rows were hidden using the normal Format|Row|Hide command, then ALL of the
> data is copied, as I first mentioned. This is true, even though AutoFilter
> essentially works by simply hiding the rows not wanted!
>
> --
> Regards,
> Bill Renaud


Thanks guys! JW, the code worked perfectly - it achieved the desired
results. I appreciate all the help and I'll make sure to keep the help
going for others.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel 2007 autofilter change to 2003 autofilter functionality? jonnybrovo815 Microsoft Excel Misc 1 19th Apr 2010 10:05 PM
2007 excel autofilter back to 2003 autofilter? jonnybrovo815 Microsoft Excel Misc 3 19th Apr 2010 08:11 PM
2007 excel autofilter change back to 2003 autofilter? jonnybrovo815 Microsoft Excel Misc 1 19th Apr 2010 05:53 PM
2007 Autofilter worse than 2003 Autofilter =?Utf-8?B?anNreQ==?= Microsoft Excel Misc 9 31st Oct 2007 12:14 AM
How to Sort within AutoFilter with Protection on (and AutoFilter . =?Utf-8?B?Z2libG9u?= Microsoft Excel Misc 1 16th Feb 2006 12:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:15 AM.