Macro is not filtering properly

TomeK712

New Member
Joined
Aug 8, 2017
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
Hi All,

Today, without any main changes in my Workbook, I found out that one of my option doesn't work.
My function is filtering database basing on values from Data Validation, that's part of my code:
Code:
  ...  
If Worksheets("MENU").CheckBoxes("CheckBox1").Value = 1 Then
        Dim lngStart As Range, lngEnd As Range
            Set lngStart = Worksheets("MENU").Range("I17")
            Set lngEnd = Worksheets("MENU").Range("K17")
                If Worksheets("MENU").Range("H11").Value = "Inbound" Then
                    Worksheets("INBOUND").Range("$A$1:$Y$2000").AutoFilter Field:=11, _
                    Criteria1:=">=" & lngStart, _
                    Operator:=xlAnd, _
                    Criteria2:="<=" & lngEnd
...
After that, all rows are hidded. When I'll click on filtered Column 11 -> Data Filters -> Between... my values are there. When I click OK it works, filtering like supposed to.
Don't know what happened, but my Workbook, even after creating different macros with set-up values to filter is not accepting macros to filter properly.

Do you know what could be the source of the issue?
30c6ayr.jpg
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Re: Macro is not filltering properly

What happens with

Code:
If Worksheets("MENU").CheckBoxes("CheckBox1").Value = 1 Then
        Dim lngStart As Range, lngEnd As Range
            Set lngStart = Worksheets("MENU").Range("I17")
            Set lngEnd = Worksheets("MENU").Range("K17")
                If Worksheets("MENU").Range("H11").Value = "Inbound" Then
                    Worksheets("INBOUND").Range("$A$1:$Y$2000").AutoFilter Field:=11, _
                    Criteria1:=">=" & [COLOR="#FF0000"]Clng[/COLOR](lngStart), _
                    Operator:=xlAnd, _
                    Criteria2:="<=" &[COLOR="#FF0000"] Clng[/COLOR](lngEnd)
 
Upvote 0
Re: Macro is not filltering properly

Brilliant! Works perfectly!
Thanks!


Edit:
Nope, actually it doesn't work. After applying the Clng it filtering the date only, without the time.

the fortmat is: dd/mm/yyyy hh:mm
 
Last edited:
Upvote 0
Re: Macro is not filltering properly

Is there option to use Clng with time, in format: dd/mm/yyyy hh:mm?
I'm looking online but nothing works.
 
Upvote 0
Re: Macro is not filltering properly

Try CDbl, a date and time is a whole number with a decimal where as a Long is a whole number only.

Not guaranteeing it will work though.
 
Last edited:
Upvote 0
Re: Macro is not filltering properly

Thank you sooo much MARK8598 it works!

Now I know to spend some time to learn about type conversion functions, cheers!
 
Upvote 0

Forum statistics

Threads
1,215,753
Messages
6,126,677
Members
449,327
Latest member
John4520

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