Autofilter a variable?

JayLee

Board Regular
Joined
Sep 23, 2002
Messages
52
I declared a variable in a userform, can I store that variable and then have it do this:

Selection.AutoFilter Field:=4, Criteria1:="=myVar

Would it work?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
On 2002-10-07 19:03, JayLee wrote:
I declared a variable in a userform, can I store that variable and then have it do this:

Selection.AutoFilter Field:=4, Criteria1:="=myVar

Would it work?

Hi JayLee:

Try ...

Selection.AutoFilter Field:=4, Criteria1:="" & [myVar] & ""

Please postback if it works for you ... otherwise explain a little further and let us take it from there.

Regards!

Yogi
 
Upvote 0
On 2002-10-07 19:03, JayLee wrote:
I declared a variable in a userform, can I store that variable and then have it do this:

Selection.AutoFilter Field:=4, Criteria1:="=myVar

Would it work?

I don't mean to be rude, but, have you tried it ?
 
Upvote 0
Nope, I tried it. It doesn't work. What happens is, it autofilters and nothing comes up. Basically, the autofilter isn't picking up the variable. Can anyone help with this?
 
Upvote 0
Here is some code to help explain myself more:

Private Sub cmdOk_Click()
Dim CurrentDate As Date
ActiveCell = cbDate.Value
ActiveCell = CurrentDate
Call DateSelect
End Sub

That's on the form.
What happens is that it doesn't seem like it's assigning the selected value to the variable, CurrentDate. I'm perhaps screwing something up here. The cbDate works perfectly displaying nonduped dates. Can some one help me with this? This is the last part of my huge project and I hope I can get this last part working! Thanks so much for everyone's help!!!!
 
Upvote 0
I figured it out, basically, I had to make the variable global like this:

Public CurrentDate As Date

So that data can be passed to the other module. Thanks guys for your insights.
 
Upvote 0
How did you get it to autofilter with a variable criteria. I set my variable public and it still isn't picking it up, its like it isn't recognizing the variable
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,988
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top