Hello all!
The other day I noticed that some code I'd written was misbehaving. On one sheet it would select the proper column and all would be well, but on another it chose the column next to it, with calamitous results. Here's the code example below:
' .Sheets("Data").Range("$A$9:$V$50000").AutoFilter Field:=5, Criteria1:=myCriteria, Operator:=xlFilterValues '
After a bit of research I found that in some cases the stuff in "Data" already had filters applied. When the filter began in Column A all was well, but sometimes it was in Column B, which caused a mess.
Simple enough solution, but I figured it would be a best practice to always include code that clears out any existing filtering. The question is, how best to do it?
I toyed with using "If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False" but if I'm not mistaken that just turns off my ability to use Filtering, which is not what I want. I also don't want to touch any data, just remove the sorting.
Suggestions?
The other day I noticed that some code I'd written was misbehaving. On one sheet it would select the proper column and all would be well, but on another it chose the column next to it, with calamitous results. Here's the code example below:
' .Sheets("Data").Range("$A$9:$V$50000").AutoFilter Field:=5, Criteria1:=myCriteria, Operator:=xlFilterValues '
After a bit of research I found that in some cases the stuff in "Data" already had filters applied. When the filter began in Column A all was well, but sometimes it was in Column B, which caused a mess.
Simple enough solution, but I figured it would be a best practice to always include code that clears out any existing filtering. The question is, how best to do it?
I toyed with using "If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False" but if I'm not mistaken that just turns off my ability to use Filtering, which is not what I want. I also don't want to touch any data, just remove the sorting.
Suggestions?