Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default auto start filtering

Hi...

I'm looking for code that will go into an auto_open macro that will
automatically filter column B6:B2000 to the value todays date [if the range
has a cell with todays value in it]. If the range doesn't have todays date in
it then no action is taken. It sounds simple but I'm struggling...

Any help appreciated...

Gordon.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default auto start filtering

Create a macro that filters for today's date. Then, in the ThisWorkbook
module, add code to the Workbook_Open event, to run that macro.

'==========================
Private Sub Workbook_Open()
FilterToday
End Sub
'===========================

'================================
'this procedure is stored in a regular module
Sub FilterToday()
Dim rng As Range
Dim rngF As Range
Dim ws As Worksheet
Dim LastRow As Long
Dim strDate As String
strDate = Format(Date, "m/d/yy")
Set ws = Sheets("Pivot Data")

'remove any existing filter
If ws.AutoFilterMode Then
ws.Cells.AutoFilter
End If

With ws
.Range("A1").AutoFilter Field:=1, _
Criteria1:=strDate
End With

Set rng = ws.AutoFilter.Range

Set rngF = Nothing
On Error Resume Next
With rng
'count the rows
Set rngF = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
End With
On Error GoTo 0

If rngF Is Nothing Then
ws.Cells.AutoFilter
End If

End Sub
'========================

Gordon wrote:
Hi...

I'm looking for code that will go into an auto_open macro that will
automatically filter column B6:B2000 to the value todays date [if the range
has a cell with todays value in it]. If the range doesn't have todays date in
it then no action is taken. It sounds simple but I'm struggling...

Any help appreciated...

Gordon.



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

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
Auto filtering kkh Excel Worksheet Functions 2 November 3rd 08 08:58 PM
auto filtering? Maggie Boby Excel Worksheet Functions 0 January 20th 08 07:30 PM
Auto Start Gerrym Excel Discussion (Misc queries) 0 March 7th 05 07:59 AM
how do I set up an auto start macro Frank Kabel Excel Programming 0 September 9th 04 10:31 PM
AUTO START JIMBO Excel Programming 2 November 20th 03 02:15 PM


All times are GMT +1. The time now is 01:16 PM.

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"