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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Yogi Anand

MrExcel MVP
Joined
Mar 12, 2002
Messages
11,454
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
 

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
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 ?
 

JayLee

Board Regular
Joined
Sep 23, 2002
Messages
52
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?
 

JayLee

Board Regular
Joined
Sep 23, 2002
Messages
52

ADVERTISEMENT

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!!!!
 

JayLee

Board Regular
Joined
Sep 23, 2002
Messages
52
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.
 

Hawk123

Board Regular
Joined
Jun 15, 2003
Messages
94
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
 

Forum statistics

Threads
1,144,150
Messages
5,722,796
Members
422,459
Latest member
Chriselff

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
Top