If And Statement

poolf01

Board Regular
Joined
Apr 24, 2007
Messages
212
I wish to write some code that if 2 conditions are met, the code will filter a list of values according to the values of MyFilter3 and MyFilter4. The code I have so far is :

If MyFilter3 <> "" And MyFilter4 <> "" Then
.AutoFilter Field:=3, Criteria1:=">=" & MyFilter3, Operator:=xlAnd, Criteria2:="<=" & MyFilter4
End If


Can someone tell me what's wrong with this? I keep getting an error message saying "Run Time Error 13, Type Mismatch"

Anybody got any ideas as I can't see that there's anything wrong with this code?! :eek:
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi poolf01 !

Did you try SQL with ADO ?

ex.
"SELECT * FROM table WHERE filter=" & Myfilter3....
 
Upvote 0
It works for me, maybe the problem is with the variables myfilter3 and 4.

Can you post the code that defines myfilter3 and 4 ?
 
Upvote 0
Hi, I think the problem was the variable that was set - I have since amended this to a String variable rather than Date and it now seems to be working. Thanks guys!
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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