当前位置: 动力学知识库 > 问答 > 编程问答 >

vba - Excel Auto filter removing by itself

问题描述:

Using Excel 2010 and have an issue that has be stumped. I have a worksheet (Supplier) that is protected. I un protect, apply Auto filter, save and then protect. When I run the below code, the Auto filter is being removed, why? The filters are on Cell A4: AO4. This is my code - it pulls data from a SQL SP into range A5:

Sheets("Supplier").Visible = True

'Unprotect worksheet

Worksheets("Supplier").Unprotect Password:="xxxxxxxxx"

'=== Code that fetches data from SQL server in to Cell A5 and below.....

Application.Goto Reference:=Worksheets("Supplier").Range("A5")

'protect worksheet

Worksheets("Supplier").Protect Password:="xxxxxxxx", AllowFormattingCells:=True, AllowFiltering:=True

I'm using the same code elsewhere and the auto filters are not removed.

网友答案:

Fixed it. I have the below code in Activation code for the supplier worksheet. I deleted this and it now works:

If ActiveSheet.AutoFilterMode Then Cells.AutoFilter
分享给朋友:
您可能感兴趣的文章:
随机阅读: