LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default need macro\method that would allow user input to a data filter

Hi CC_rider,

Try:

'=================
Sub Tester02A()
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim SH1 As Worksheet
Dim SH2 As Worksheet
Dim rng As Range
Dim sStr As String

Set WB1 = Workbooks("Daily purchase parts list.xls")
Set WB2 = Workbooks("Pump tester.xls")

Set SH1 = WB2.Sheets("Sheet1") '<== CHANGE Sheet name
Set SH2 = WB1.Sheets("Sheet3") '<== CHANGE sheet name

sStr = SH1.Range("a1").Value '<<== CHANGE cell reference

Set rng = SH2.AutoFilter.Range

With rng
.AutoFilter Field:=1, Criteria1:=sStr, Operator:=xlAnd
.AutoFilter Field:=2, Criteria1:="=4", Operator:=xlOr, _
Criteria2:="10"
End With
End Sub

'<<=================

Change the two sheet names to match your actual sheet names. Change the cell
reference also.


---
Regards,
Norman



"CC_rider" wrote in message
...
NJ - I meant to say.."...I need to reference a cell in another WORKBOOK
(file) not sheet " ...(pls bear w\me-THX)

P.S. To make it easier for me to deciper could you use my filenames in the
macro : (1st) "Daily purchase parts list.xls" (file that has the auto
filter)
and (2nd)"Pump tester.xls" ( file that will contain the macro and also the
cell reference for the criteria needed in the auto filter )

"Norman Jones" wrote:

Hi CC_rider

There are a couple of syntax errors in your code.

Additionally, it is unnecessary to make selecttions here.

Try instead, something like:

'=======================
Sub Tester02()
Dim WB As Workbook
Dim SH1 As Worksheet
Dim SH2 As Worksheet
Dim rng As Range
Dim sStr As String

Set WB = ActiveWorkbook '<==== CHANGE
Set SH1 = WB.Sheets("Sheet1") '<==== CHANGE
Set SH2 = WB.Sheets("Sheet3") '<==== CHANGE

sStr = SH1.Range("a1").Value '<==== CHANGE

Set rng = SH2.AutoFilter.Range

With rng
.AutoFilter Field:=1, Criteria1:=sStr, Operator:=xlAnd
.AutoFilter Field:=2, Criteria1:="=4", Operator:=xlOr, _
Criteria2:="10"
End With

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

Change the indicated values to accord with your own data.


---
Regards,
Norman



"CC_rider" wrote in message
...
THX NJ (much love)-
What you gave me got me started but I'm only half way there ...
I need to be able reference a cell from "another sheet" to use as
criteria
for the autofilter field:1.So I changed what you gave me (below) but
it
still doesn't work ...Is the syntax wrong or something ?!?

Windows("Sheet1").Activate

Dim rng As Range

Set rng = ActiveSheet.AutoFilter.Range

With rng
.AutoFilter Field:=1,
Criteria1:=sheets("anothersheet").Range("a1"),valu e,_Operator:=xlAnd
.AutoFilter Field:=2, Criteria1:="=4", Operator:=xlOr, _
Criteria2:="10"

"Norman Jones" wrote:

Hi CC_rider,

Perhaps something like:

'====================
Public Sub Tester01()
Dim rng As Range

Set rng = ActiveSheet.AutoFilter.Range

With rng
.AutoFilter Field:=1, Criteria1:="ABC", Operator:=xlAnd
.AutoFilter Field:=2, Criteria1:="=4", Operator:=xlOr, _
Criteria2:="10"
End With
End Sub
'<<====================


---
Regards,
Norman



"CC_rider" wrote in message
...
Any ideals on how I would go about setting up a macro to allow me to
input
search criteria into a data filter ?








 
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
Need macro to post data from user input Azrael[_3_] Excel Worksheet Functions 3 March 8th 09 09:40 PM
macro to save as a data input by user file name from a designated Brian Excel Discussion (Misc queries) 2 November 20th 07 04:00 AM
Restrict-Filter-Limit-Validate user input in Excel Dr. Thom Excel Discussion (Misc queries) 0 January 22nd 06 08:06 PM
Find method using User input Cory Thomas[_4_] Excel Programming 1 June 8th 04 10:12 PM
Can a macro be suspended during user input? David DeArmond Excel Programming 2 August 1st 03 05:02 AM


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