Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Using a macro to control the autofilter function


I am trying to write a macro which filters a table of data using
criteria determined in another worksheet.

This is the code that I produced to date. The variables Cruiseline1
and cruiseline2 work fine however I want to be able to filter a date
range as well. I cannot get the greater than equals to command to
work.

Any suggestions?

Dim Cruiseline1
Dim Cruiseline2
Dim Date1
Dim Date2

Cruiseline1 = Worksheets("Front Sheet").Range("b3").Value
Cruiseline2 = Worksheets("Front Sheet").Range("b4").Value
Date1 = Worksheets("Front Sheet").Range("c6").Value
Date2 = Worksheets("Front Sheet").Range("c7").Value

Selection.AutoFilter Field:=5, Criteria1:=Cruiseline1, _
Operator:=xlOr, Criteria2:=Cruiseline2

Selection.AutoFilter Field:=1, Criteria1:=Format(Date1,
Selection.Cells(2, 1).NumberFormat), _
Operator:=xlAnd, Criteria2:<=Format(Date2, Selection.Cells(2,
1).NumberFormat)




--
APealin
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Using a macro to control the autofilter function

APealin,

Remember, the macro recorder is your friend for helping figure out the correct syntax....

Selection.AutoFilter Field:=1, Criteria1:="=" & Format(Date1, Selection.Cells(2, 1).NumberFormat),
_
Operator:=xlAnd, Criteria2:="<=" & Format(Date2, Selection.Cells(2, 1).NumberFormat)


HTH,
Bernie
MS Excel MVP


"APealin" wrote in message
...

I am trying to write a macro which filters a table of data using
criteria determined in another worksheet.

This is the code that I produced to date. The variables Cruiseline1
and cruiseline2 work fine however I want to be able to filter a date
range as well. I cannot get the greater than equals to command to
work.

Any suggestions?

Dim Cruiseline1
Dim Cruiseline2
Dim Date1
Dim Date2

Cruiseline1 = Worksheets("Front Sheet").Range("b3").Value
Cruiseline2 = Worksheets("Front Sheet").Range("b4").Value
Date1 = Worksheets("Front Sheet").Range("c6").Value
Date2 = Worksheets("Front Sheet").Range("c7").Value

Selection.AutoFilter Field:=5, Criteria1:=Cruiseline1, _
Operator:=xlOr, Criteria2:=Cruiseline2

Selection.AutoFilter Field:=1, Criteria1:=Format(Date1,
Selection.Cells(2, 1).NumberFormat), _
Operator:=xlAnd, Criteria2:<=Format(Date2, Selection.Cells(2,
1).NumberFormat)




--
APealin



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Using a macro to control the autofilter function

Dim Cruiseline1
Dim Cruiseline2
Dim Date1
Dim Date2

Cruiseline1 = Worksheets("Front Sheet").Range("b3").Value
Cruiseline2 = Worksheets("Front Sheet").Range("b4").Value
Date1 = Worksheets("Front Sheet").Range("c6").Value
Date2 = Worksheets("Front Sheet").Range("c7").Value

Selection.AutoFilter Field:=5, _
Criteria1:=Cruiseline1, _
Operator:=xlOr, _
Criteria2:=Cruiseline2

With Selection
.AutoFilter Field:=1, _
Criteria1:="=" & Format(Date1, .Cells(2, 1).NumberFormat),
_
Operator:=xlAnd, _
Criteria2:="<=" & Format(Date2, .Cells(2, 1).NumberFormat)
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"APealin" wrote in message
...

I am trying to write a macro which filters a table of data using
criteria determined in another worksheet.

This is the code that I produced to date. The variables Cruiseline1
and cruiseline2 work fine however I want to be able to filter a date
range as well. I cannot get the greater than equals to command to
work.

Any suggestions?

Dim Cruiseline1
Dim Cruiseline2
Dim Date1
Dim Date2

Cruiseline1 = Worksheets("Front Sheet").Range("b3").Value
Cruiseline2 = Worksheets("Front Sheet").Range("b4").Value
Date1 = Worksheets("Front Sheet").Range("c6").Value
Date2 = Worksheets("Front Sheet").Range("c7").Value

Selection.AutoFilter Field:=5, Criteria1:=Cruiseline1, _
Operator:=xlOr, Criteria2:=Cruiseline2

Selection.AutoFilter Field:=1, Criteria1:=Format(Date1,
Selection.Cells(2, 1).NumberFormat), _
Operator:=xlAnd, Criteria2:<=Format(Date2, Selection.Cells(2,
1).NumberFormat)




--
APealin



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
Control button / macro Sarah Excel Discussion (Misc queries) 2 February 11th 07 04:45 AM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
autofilter macro flow23 Excel Discussion (Misc queries) 1 April 18th 06 03:00 PM
Keep autofilter after macro is run gmr7 Excel Worksheet Functions 2 July 5th 05 01:16 PM
Autofilter Macro Help RonB Excel Discussion (Misc queries) 1 December 30th 04 01:34 AM


All times are GMT +1. The time now is 08:32 AM.

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"