Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Auto filter using macro not woking

Dear All,

I have a column of dates, past & future. It may or may not have
current date. I am trying to auto filter to view only those rows that
contains dates of future (as of current date) . Manually this is fine
but when I try to recorded macro this as macro and edit it to modify
condition as

Selection.AutoFilter Field:=27, Criteria1:="=" & today(),
Operator:=xlAnd

It gives an error, "Compile Error: Sub or function not defined"

Following is my entire code

Sub accrual_swap()
'
' accrual_swap Macro
' Macro recorded 6/6/2007 by Ashish Sharma
'

'

Range("AA1").Select
Rows("1:1").Select
Range("AA1").Activate
Selection.Insert Shift:=xlDown
Selection.AutoFilter
Range("AA1").Select
Selection.AutoFilter Field:=27, Criteria1:="=" & today(),
Operator:=xlAnd
' Following was original line of code
' Selection.AutoFilter Field:=27, Criteria1:="6/4/2007",
Operator:=xlAnd
Columns("A:Y").Select
Range("Y1").Activate
Selection.Delete Shift:=xlToLeft
Columns("C:L").Select
Selection.Delete Shift:=xlToLeft
Range("A21:A79").Select
End Sub

Please help

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Auto filter using macro not woking

=today() is a worksheet function--you'd use it in a cell when you're writing a
formula.

I'd try this:
Selection.AutoFilter Field:=27, Criteria1:="=" & date

but filtering dates can be tricky.

This may work if the first doesn't:
Selection.AutoFilter Field:=27, Criteria1:="=" & clng(date)

And one more--just in case:
Selection.AutoFilter Field:=27, Criteria1:="=" & format(date,"m/d/yyyy")

Match the date format to what you use in the worksheet.


ashish128 wrote:

Dear All,

I have a column of dates, past & future. It may or may not have
current date. I am trying to auto filter to view only those rows that
contains dates of future (as of current date) . Manually this is fine
but when I try to recorded macro this as macro and edit it to modify
condition as

Selection.AutoFilter Field:=27, Criteria1:="=" & today(),
Operator:=xlAnd

It gives an error, "Compile Error: Sub or function not defined"

Following is my entire code

Sub accrual_swap()
'
' accrual_swap Macro
' Macro recorded 6/6/2007 by Ashish Sharma
'

'

Range("AA1").Select
Rows("1:1").Select
Range("AA1").Activate
Selection.Insert Shift:=xlDown
Selection.AutoFilter
Range("AA1").Select
Selection.AutoFilter Field:=27, Criteria1:="=" & today(),
Operator:=xlAnd
' Following was original line of code
' Selection.AutoFilter Field:=27, Criteria1:="6/4/2007",
Operator:=xlAnd
Columns("A:Y").Select
Range("Y1").Activate
Selection.Delete Shift:=xlToLeft
Columns("C:L").Select
Selection.Delete Shift:=xlToLeft
Range("A21:A79").Select
End Sub

Please help


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Auto filter using macro not woking

On Jun 6, 5:44 pm, Dave Peterson wrote:
=today() is a worksheet function--you'd use it in a cell when you're writing a
formula.

I'd try this:
Selection.AutoFilter Field:=27, Criteria1:="=" & date

but filtering dates can be tricky.

This may work if the first doesn't:
Selection.AutoFilter Field:=27, Criteria1:="=" & clng(date)

And one more--just in case:
Selection.AutoFilter Field:=27, Criteria1:="=" & format(date,"m/d/yyyy")

Match the date format to what you use in the worksheet.





ashish128 wrote:

Dear All,


I have a column of dates, past & future. It may or may not have
current date. I am trying to auto filter to view only those rows that
contains dates of future (as of current date) . Manually this is fine
but when I try to recorded macro this as macro and edit it to modify
condition as


Selection.AutoFilter Field:=27, Criteria1:="=" & today(),
Operator:=xlAnd


It gives an error, "Compile Error: Sub or function not defined"


Following is my entire code


Sub accrual_swap()
'
' accrual_swap Macro
' Macro recorded 6/6/2007 by Ashish Sharma
'


'


Range("AA1").Select
Rows("1:1").Select
Range("AA1").Activate
Selection.Insert Shift:=xlDown
Selection.AutoFilter
Range("AA1").Select
Selection.AutoFilter Field:=27, Criteria1:="=" & today(),
Operator:=xlAnd
' Following was original line of code
' Selection.AutoFilter Field:=27, Criteria1:="6/4/2007",
Operator:=xlAnd
Columns("A:Y").Select
Range("Y1").Activate
Selection.Delete Shift:=xlToLeft
Columns("C:L").Select
Selection.Delete Shift:=xlToLeft
Range("A21:A79").Select
End Sub


Please help


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Thanks Friend,

I tried the second otion

Selection.AutoFilter Field:=27, Criteria1:="=" & clng(date)

and it worked for me.

Thanks a lot.

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 filter within a macro Sean Excel Discussion (Misc queries) 4 March 27th 08 11:04 AM
Allow Auto Filter Within Macro in Excel 2003 (SP2) Pank New Users to Excel 2 May 14th 07 08:48 AM
Auto filter run from a macro will not do the same as when done manually. ChemicalJasper Excel Discussion (Misc queries) 0 February 2nd 07 03:25 PM
Auto filter run from a macro will not do the same as when done manually. ChemicalJasper Excel Discussion (Misc queries) 0 February 2nd 07 03:25 PM
Auto Filter Macro Snakeoids Excel Discussion (Misc queries) 10 August 24th 05 08:46 PM


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