Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Hi Everyone
This macro works ok on the open worksheet. I would like to filter all worksheets
in the workbook
Sub Filter()
For Each wks In Selection
Selection.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 4, 1),
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 4, 30)
Next wks
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Apply macro to all worksheets

On Jun 22, 8:28*am, "Cimjet" wrote:
Hi Everyone
This macro works ok on the open worksheet. I would like to filter all worksheets
in the workbook
Sub Filter()
* * * * For Each wks In Selection
* * Selection.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 4, 1),
Operator:=xlAnd, _
* * * * Criteria2:="<" & DateSerial(2011, 4, 30)
* * * * * * * * * *Next wks
* * *End Sub


for each wks in worksheets
ws.autofilter
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Hi Don
See my other post ("Custom Filter")
"Don Guillett" wrote in message
...
On Jun 22, 8:28 am, "Cimjet" wrote:
Hi Everyone
This macro works ok on the open worksheet. I would like to filter all
worksheets
in the workbook
Sub Filter()
For Each wks In Selection
Selection.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 4, 1),
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 4, 30)
Next wks
End Sub


for each wks in worksheets
ws.autofilter

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Hi Don
For each wks in worksheets ---that works ok but
ws.autofilter ----that gave me an error. Run time error 448---Named argument
not found.

here is the macro..
Sub Filter()
For Each ws In Worksheets
ws.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 3, 1),
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 3, 30)
Next ws
End Sub
Regards
Cimjet
"Don Guillett" wrote in message
...
On Jun 22, 8:28 am, "Cimjet" wrote:
Hi Everyone
This macro works ok on the open worksheet. I would like to filter all
worksheets
in the workbook
Sub Filter()
For Each wks In Selection
Selection.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 4, 1),
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 4, 30)
Next wks
End Sub


for each wks in worksheets
ws.autofilter

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Apply macro to all worksheets

Hi Cimjet,

Am Wed, 22 Jun 2011 12:38:57 -0400 schrieb Cimjet:

Sub Filter()
For Each ws In Worksheets
ws.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 3, 1),
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 3, 30)
Next ws
End Sub


you have to activate each worksheet or you have to write "With ws"
Try this:
For Each ws In Worksheets
With ws.UsedRange
.AutoFilter , Field:=2, _
Criteria1:="" & DateSerial(2011, 3, 1), _
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 3, 30)
End With
Next ws


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Hi Claus
It's not working properly. I get this message..plus it's not filtering all
sheets, one is left out.
Run time error 1004---AutoFilter method of range class failed.
Claus, see my other post "Custom Filter" I'm getting the same error. but it's
filtering all sheets.
Any help would be appreciated.
Cimjet


"Claus Busch" wrote in message
...
Hi Cimjet,

Am Wed, 22 Jun 2011 12:38:57 -0400 schrieb Cimjet:

Sub Filter()
For Each ws In Worksheets
ws.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 3, 1),
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 3, 30)
Next ws
End Sub


you have to activate each worksheet or you have to write "With ws"
Try this:
For Each ws In Worksheets
With ws.UsedRange
.AutoFilter , Field:=2, _
Criteria1:="" & DateSerial(2011, 3, 1), _
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 3, 30)
End With
Next ws


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Claus
Correction it's not filtering all sheets, it's leaving one out just like yours
"Cimjet" wrote in message
...
Hi Claus
It's not working properly. I get this message..plus it's not filtering all
sheets, one is left out.
Run time error 1004---AutoFilter method of range class failed.
Claus, see my other post "Custom Filter" I'm getting the same error. but it's
filtering all sheets.
Any help would be appreciated.
Cimjet


"Claus Busch" wrote in message
...
Hi Cimjet,

Am Wed, 22 Jun 2011 12:38:57 -0400 schrieb Cimjet:

Sub Filter()
For Each ws In Worksheets
ws.AutoFilter Field:=2, Criteria1:="" & DateSerial(2011, 3, 1),
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 3, 30)
Next ws
End Sub


you have to activate each worksheet or you have to write "With ws"
Try this:
For Each ws In Worksheets
With ws.UsedRange
.AutoFilter , Field:=2, _
Criteria1:="" & DateSerial(2011, 3, 1), _
Operator:=xlAnd, _
Criteria2:="<" & DateSerial(2011, 3, 30)
End With
Next ws


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Apply macro to all worksheets

Hi Cimjet,

Am Wed, 22 Jun 2011 13:26:27 -0400 schrieb Cimjet:

Correction it's not filtering all sheets, it's leaving one out just like yours


in my workbook it's filtering all sheets. Only DateSerial is not
working. Autofilter in VBA needs the date in MM/DD/YYYY.
If I try:
..AutoFilter Field:=2, Criteria1:="03/01/2011", _
Operator:=xlAnd, Criteria2:="<03/30/2011"

or if I put dates in F1 and F2 and try:
..AutoFilter Field:=2, _
Criteria1:="" & Range("F1").Value2, _
Operator:=xlAnd, _
Criteria2:="<" & Range("F2").Value2

everything works fine.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Hi Claus
I'm still getting the same error. I place the proper dates in F1 and G1
Sub Filter()
For Each wsh In Worksheets
With wsh
If Not .FilterMode Then .Range("B5").AutoFilter
.Range("B5").AutoFilter , Field:=2, Criteria1:="" & Range("F1").Value2, _
Operator:=xlAnd, Criteria2:="<" & Range("G1").Value2
End With
Next
End Sub

"Claus Busch" wrote in message
...
Hi Cimjet,

Am Wed, 22 Jun 2011 13:26:27 -0400 schrieb Cimjet:

Correction it's not filtering all sheets, it's leaving one out just like
yours


in my workbook it's filtering all sheets. Only DateSerial is not
working. Autofilter in VBA needs the date in MM/DD/YYYY.
If I try:
.AutoFilter Field:=2, Criteria1:="03/01/2011", _
Operator:=xlAnd, Criteria2:="<03/30/2011"

or if I put dates in F1 and F2 and try:
.AutoFilter Field:=2, _
Criteria1:="" & Range("F1").Value2, _
Operator:=xlAnd, _
Criteria2:="<" & Range("F2").Value2

everything works fine.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Apply macro to all worksheets

Hi Cimjet,

Am Wed, 22 Jun 2011 13:43:48 -0400 schrieb Cimjet:

I'm still getting the same error. I place the proper dates in F1 and G1
Sub Filter()
For Each wsh In Worksheets
With wsh
If Not .FilterMode Then .Range("B5").AutoFilter
.Range("B5").AutoFilter , Field:=2, Criteria1:="" & Range("F1").Value2, _
Operator:=xlAnd, Criteria2:="<" & Range("G1").Value2
End With
Next
End Sub


here everything works fine. But I have to start the macro from the sheet
in which the date is placed or I have to reference it with sheetname.
Where did your code stop? Write in first line of module:
Option Explicit
Then you have to declare wsh as worksheet, but you see where your code
stops.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Claus
It's stoping at " .Range("B5").AutoFilter" and same error.
Run time error 1004---AutoFilter method of range class failed.

"Claus Busch" wrote in message
...
Hi Cimjet,

Am Wed, 22 Jun 2011 13:43:48 -0400 schrieb Cimjet:

I'm still getting the same error. I place the proper dates in F1 and G1
Sub Filter()
For Each wsh In Worksheets
With wsh
If Not .FilterMode Then .Range("B5").AutoFilter
.Range("B5").AutoFilter , Field:=2, Criteria1:="" & Range("F1").Value2,
_
Operator:=xlAnd, Criteria2:="<" & Range("G1").Value2
End With
Next
End Sub


here everything works fine. But I have to start the macro from the sheet
in which the date is placed or I have to reference it with sheetname.
Where did your code stop? Write in first line of module:
Option Explicit
Then you have to declare wsh as worksheet, but you see where your code
stops.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Claus
The problem is on my copy. Isabelle sent me a sample file and it works fine, it
looks like the problem is on my copy only.
Cimjet
"Cimjet" wrote in message
...
Claus
It's stoping at " .Range("B5").AutoFilter" and same error.
Run time error 1004---AutoFilter method of range class failed.

"Claus Busch" wrote in message
...
Hi Cimjet,

Am Wed, 22 Jun 2011 13:43:48 -0400 schrieb Cimjet:

I'm still getting the same error. I place the proper dates in F1 and G1
Sub Filter()
For Each wsh In Worksheets
With wsh
If Not .FilterMode Then .Range("B5").AutoFilter
.Range("B5").AutoFilter , Field:=2, Criteria1:="" & Range("F1").Value2,
_
Operator:=xlAnd, Criteria2:="<" & Range("G1").Value2
End With
Next
End Sub


here everything works fine. But I have to start the macro from the sheet
in which the date is placed or I have to reference it with sheetname.
Where did your code stop? Write in first line of module:
Option Explicit
Then you have to declare wsh as worksheet, but you see where your code
stops.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Apply macro to all worksheets

Hi Cimjet,

Am Wed, 22 Jun 2011 15:22:53 -0400 schrieb Cimjet:

The problem is on my copy. Isabelle sent me a sample file and it works fine, it
looks like the problem is on my copy only.


thank you for the feedback.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Apply macro to all worksheets

may be that this sheet is protected ?

--
isabelle

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Hi Isabelle
No the sheets and the workbook are not protected
"isabelle" wrote in message ...
may be that this sheet is protected ?

--
isabelle



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Apply macro to all worksheets

Hi Claus
Just for information, I thought you would like to know, I found the problem.
My workbook has around 16 worksheets and one of them was empty, that was causing
the problem plus one sheet I had to place an autofilter on the heading and
that's it, it works like a charm.
Cimjet

"Claus Busch" wrote in message
...
Hi Cimjet,

Am Wed, 22 Jun 2011 15:22:53 -0400 schrieb Cimjet:

The problem is on my copy. Isabelle sent me a sample file and it works fine,
it
looks like the problem is on my copy only.


thank you for the feedback.


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


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
Apply Macro to all worksheets in a workbook except one Carrie_Loos via OfficeKB.com Excel Discussion (Misc queries) 5 January 15th 09 10:03 PM
automatically apply a macro to all worksheets minrufeng Excel Discussion (Misc queries) 5 February 21st 06 09:34 PM
Apply Macro on Multiple Worksheets in a Workbook Agnes Excel Programming 0 September 24th 04 01:39 AM
Apply Macro on Multiple Worksheets in a Workbook Agnes Excel Programming 1 September 23rd 04 06:56 PM
Apply Macro on Multiple Worksheets in a Workbook Agnes Excel Programming 1 September 23rd 04 02:20 AM


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