Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default autofilter using string input

The following macro doesn't return any records.

Sub filtering()
Dim StartDate As String
Dim cStartDate As String
Dim cEndDate As String

StartDate = ActiveSheet.Cells(1, 4).Value
cStartDate = "=" & StartDate
cEndDate = "<=" & ActiveSheet.Cells(1, 4).Value + 6

ActiveSheet.Cells(5, 1).Select
Selection.AutoFilter Field:=8, Criteria1:=cStartDate, _
Operator:=xlAnd, Criteria2:=cEndDate
End Sub

However, when I go manually go to check the autofilter
(custom...) window and then click OK, I get the expected
result of the filter.

It seems the criteria for the filter aren't working very
well programatically. How can I overcome this?

TIA for assistance.
KT
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default autofilter using string input

Have you tried turning on the macro recorder, setting up the filter, then
stopping the recorder and looking at the code. Maybe it will give you the
needed clue.

On Wed, 27 Oct 2004 19:50:31 -0700, "KT"
wrote:

The following macro doesn't return any records.

Sub filtering()
Dim StartDate As String
Dim cStartDate As String
Dim cEndDate As String

StartDate = ActiveSheet.Cells(1, 4).Value
cStartDate = "=" & StartDate
cEndDate = "<=" & ActiveSheet.Cells(1, 4).Value + 6

ActiveSheet.Cells(5, 1).Select
Selection.AutoFilter Field:=8, Criteria1:=cStartDate, _
Operator:=xlAnd, Criteria2:=cEndDate
End Sub

However, when I go manually go to check the autofilter
(custom...) window and then click OK, I get the expected
result of the filter.

It seems the criteria for the filter aren't working very
well programatically. How can I overcome this?

TIA for assistance.
KT


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default autofilter using string input

BTW, the code results in the correct fields being
populated in the Custom AutoFilter dialog box - but for
some reason Excel doesn't filter correctly.

-----Original Message-----
Have you tried turning on the macro recorder, setting up

the filter, then
stopping the recorder and looking at the code. Maybe it

will give you the
needed clue.

On Wed, 27 Oct 2004 19:50:31 -0700, "KT"


wrote:

The following macro doesn't return any records.

Sub filtering()
Dim StartDate As String
Dim cStartDate As String
Dim cEndDate As String

StartDate = ActiveSheet.Cells(1, 4).Value
cStartDate = "=" & StartDate
cEndDate = "<=" & ActiveSheet.Cells(1, 4).Value + 6

ActiveSheet.Cells(5, 1).Select
Selection.AutoFilter Field:=8,

Criteria1:=cStartDate, _
Operator:=xlAnd, Criteria2:=cEndDate
End Sub

However, when I go manually go to check the autofilter
(custom...) window and then click OK, I get the expected
result of the filter.

It seems the criteria for the filter aren't working very
well programatically. How can I overcome this?

TIA for assistance.
KT


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default autofilter using string input

Sometimes, if you convert the dates to longs, it helps:

cStartDate = "=" & StartDate
cEndDate = "<=" & ActiveSheet.Cells(1, 4).Value + 6

cStartDate = "=" & clng(StartDate)
cEndDate = "<=" & clng(ActiveSheet.Cells(1, 4).Value) + 6

But dates can be problems in autofilters via code.


KT wrote:

The following macro doesn't return any records.

Sub filtering()
Dim StartDate As String
Dim cStartDate As String
Dim cEndDate As String

StartDate = ActiveSheet.Cells(1, 4).Value
cStartDate = "=" & StartDate
cEndDate = "<=" & ActiveSheet.Cells(1, 4).Value + 6

ActiveSheet.Cells(5, 1).Select
Selection.AutoFilter Field:=8, Criteria1:=cStartDate, _
Operator:=xlAnd, Criteria2:=cEndDate
End Sub

However, when I go manually go to check the autofilter
(custom...) window and then click OK, I get the expected
result of the filter.

It seems the criteria for the filter aren't working very
well programatically. How can I overcome this?

TIA for assistance.
KT


--

Dave Peterson

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
How to avoid duplicate string value input in one column? Wavelet Excel Worksheet Functions 1 March 30th 07 05:04 AM
Applying an AutoFilter to a string Hardip Excel Discussion (Misc queries) 3 April 16th 06 05:32 PM
Use sheet name as search string or autofilter criteria Magar Excel Programming 1 November 14th 03 01:06 PM
Access AutoFilter list for use with input box? Ed[_9_] Excel Programming 4 November 4th 03 01:51 PM
Autofilter input Abdul Salam Excel Programming 1 August 11th 03 02:41 PM


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