Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Newbie : Autofilter thru code ?

I am using Excel 97.

I am getting started with Excel VBA coding. I wanted to now is it
possible to apply an Autofilter with VBA coding. The reason I asked is
because when I tried to record a key stroke macro with an autofilter,
the spreadsheet did not record something that I can use.

So what lines a code do I need to filter data.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Newbie : Autofilter thru code ?

Rich,

Excel doesn't record key stroke macros. I builds VBA, a mix of the old
BASIC language, and the Excel object model (which gives you access to all
kinds of Excel stuff, like cells, sheets, operations (methods)).

These two are essentially equivalent. They turn on Autofilter for the range
(which gets expanded) A1:

Range("A1").Select
Selection.AutoFilter

Range("A1").Autofilter

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"Rich" wrote in message
om...
I am using Excel 97.

I am getting started with Excel VBA coding. I wanted to now is it
possible to apply an Autofilter with VBA coding. The reason I asked is
because when I tried to record a key stroke macro with an autofilter,
the spreadsheet did not record something that I can use.

So what lines a code do I need to filter data.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,268
Default Newbie : Autofilter thru code ?

Here's an example that I use at work

Sub Area_Code()
Application.ScreenUpdating = False
UserVal = Application.InputBox("Enter Area Code")
If UserVal = False Then
Exit Sub
Else
Selection.AutoFilter Field:=4, Criteria1:=UserVal & "*", Operator:=xlAnd
End If
Application.ScreenUpdating = True
End Sub

I have this attached to a forms puch button when I want to filter on area
code,
the above use an input box where I type the area code

Obviosuly you won't need that, you could use

Sub FilterMe()
Application.ScreenUpdating = False
Selection.AutoFilter Field:=1, Criteria1:="10"
Application.ScreenUpdating = True
End Sub

This will filter on the first column, using 10 as crieria.

To reset w/o turning off the filter you could use

Sub Reset_Filter()
Application.ScreenUpdating = False
For Each sh In Worksheets
If sh.FilterMode Then
On Error Resume Next
sh.ShowAllData
End If
Next
Range("A1").Select
Application.ScreenUpdating = True
End Sub

--

Regards,

Peo Sjoblom



"Rich" wrote in message
om...
I am using Excel 97.

I am getting started with Excel VBA coding. I wanted to now is it
possible to apply an Autofilter with VBA coding. The reason I asked is
because when I tried to record a key stroke macro with an autofilter,
the spreadsheet did not record something that I can use.

So what lines a code do I need to filter data.



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
Excel vba autofilter code Isis[_2_] Excel Discussion (Misc queries) 0 April 26th 10 05:34 PM
Excel VBA AutoFilter code Isis[_2_] Excel Discussion (Misc queries) 0 April 26th 10 05:31 PM
vba code on autofilter ub Excel Discussion (Misc queries) 1 August 6th 08 08:09 PM
Autofilter code Dominic LeVasseur Excel Discussion (Misc queries) 2 August 16th 06 09:33 PM
VBA Newbie: Help with Do Loop code Carl Excel Discussion (Misc queries) 3 December 2nd 04 07:04 PM


All times are GMT +1. The time now is 01:51 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"