Darren Bartrup
Well-known Member
- Joined
- Mar 13, 2006
- Messages
- 1,297
- Office Version
- 365
- Platform
- Windows
Hi all,
I'm having an annoying problem where I have a small routine to filter a data range to whichever column and argument I pass to it.
I've put the routine at the end of this post.
It's called using this:
This is meant to filter by column 7 equaling todays date and column 13 is blank, but it misses the last row (which meets the criteria and should be shown but is hidden instead).
My workbook doesn't have any subtotals, rMainData references the whole range in question.
I've tried changing DateValue(Date) to:
DateSerial(Year(Date),Month(Date),Day(Date)) and
Format(DateValue(Date),"dd/mm/yyyy") but that doesn't work.
I've tried extending the range by another row - still misses it.
The only way I can get it to work is by filtering it manually - which I can't do for this project.
The filtering procedure is here and it works most of the time, just not now
Any help why it's doing this will be most welcome.
Regards,
Darren.
I'm having an annoying problem where I have a small routine to filter a data range to whichever column and argument I pass to it.
I've put the routine at the end of this post.
It's called using this:
Code:
SetFilter rMainData, Array(7, "=" & DateValue(Date)), Array(13, "=")
This is meant to filter by column 7 equaling todays date and column 13 is blank, but it misses the last row (which meets the criteria and should be shown but is hidden instead).
My workbook doesn't have any subtotals, rMainData references the whole range in question.
I've tried changing DateValue(Date) to:
DateSerial(Year(Date),Month(Date),Day(Date)) and
Format(DateValue(Date),"dd/mm/yyyy") but that doesn't work.
I've tried extending the range by another row - still misses it.
The only way I can get it to work is by filtering it manually - which I can't do for this project.
The filtering procedure is here and it works most of the time, just not now

Code:
Public Sub SetFilter(rDataRange As Range, ParamArray sFilters())
Dim wrkSht As Worksheet
Dim x As Long
Set wrkSht = rDataRange.Parent 'Get reference to worksheet.
With wrkSht
If Not .AutoFilterMode Then rDataRange.AutoFilter 'Turn on the auto-filter
If .FilterMode Then .ShowAllData 'Clear any filters applied.
End With
With rDataRange
For x = LBound(sFilters) To UBound(sFilters)
Select Case UBound(sFilters(x))
Case 1 '2 elements to array.
.AutoFilter Field:=sFilters(x)(0), Criteria1:=sFilters(x)(1)
Case 3 '4 elements to array.
.AutoFilter Field:=sFilters(x)(0), Criteria1:=sFilters(x)(1), _
Operator:=sFilters(x)(3), Criteria2:=sFilters(x)(2)
End Select
Next x
End With
End Sub
Any help why it's doing this will be most welcome.
Regards,
Darren.