K
KenY
Hi
Got a problem that is driving me daft. Have looked at past threads and got
some help, but nothing to fix what I am seeing now.
I have a piece of code that is filtering a data list for a particular value
(in variable "tallyfilter"). When the data I am looking for starts on row 2
of the data table (row 1 has headers), I get the correct row count. However,
a specific instance that has me beaten at the moment is a dataset where the
target value starts on row 135. The row count is returned as '1' (=no data
visible) when in fact the data is actually filtered and visible when I look a
the spreadsheet in debug mode.
Is there anything wrong with my code? Looking at other threads I cannot
spot any errors and I am beginning to think there may be some unusual
character in my datalist. I have left in one suggested fix which was to use
the 'no data returned' error as my condition - unfortunately, it made no
difference as no error was reported (it saw data, but the rows.count didn't)!
fyi, I added a statement to select the whole data region before filtering;
when I did this and bypassed the condition rcntr=1, I did get the filtered
data to copy (but that gave me another problem, so I need to return the
correct row count).
Code is:
....
If tallyfilter = "ALL" Then
Else: Rows("1:1").Select
Selection.AutoFilter
Range("A1").Select
Selection.CurrentRegion.Select
Selection.AutoFilter Field:=2, Criteria1:=tallyfilter
End If
' count the number of rows in filtered data and exit if only the header is
present
rcntr = Selection.CurrentRegion.SpecialCells(xlVisible).Rows.Count
If rcntr = 1 Then Exit Sub
On Error GoTo nothing_to_copy
Selection.CurrentRegion.SpecialCells(xlVisible).Copy
On Error GoTo 0
....
Would be grateful if someone can help me out on this.
Thanks
Got a problem that is driving me daft. Have looked at past threads and got
some help, but nothing to fix what I am seeing now.
I have a piece of code that is filtering a data list for a particular value
(in variable "tallyfilter"). When the data I am looking for starts on row 2
of the data table (row 1 has headers), I get the correct row count. However,
a specific instance that has me beaten at the moment is a dataset where the
target value starts on row 135. The row count is returned as '1' (=no data
visible) when in fact the data is actually filtered and visible when I look a
the spreadsheet in debug mode.
Is there anything wrong with my code? Looking at other threads I cannot
spot any errors and I am beginning to think there may be some unusual
character in my datalist. I have left in one suggested fix which was to use
the 'no data returned' error as my condition - unfortunately, it made no
difference as no error was reported (it saw data, but the rows.count didn't)!
fyi, I added a statement to select the whole data region before filtering;
when I did this and bypassed the condition rcntr=1, I did get the filtered
data to copy (but that gave me another problem, so I need to return the
correct row count).
Code is:
....
If tallyfilter = "ALL" Then
Else: Rows("1:1").Select
Selection.AutoFilter
Range("A1").Select
Selection.CurrentRegion.Select
Selection.AutoFilter Field:=2, Criteria1:=tallyfilter
End If
' count the number of rows in filtered data and exit if only the header is
present
rcntr = Selection.CurrentRegion.SpecialCells(xlVisible).Rows.Count
If rcntr = 1 Then Exit Sub
On Error GoTo nothing_to_copy
Selection.CurrentRegion.SpecialCells(xlVisible).Copy
On Error GoTo 0
....
Would be grateful if someone can help me out on this.
Thanks