ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need Excel macro to turn off AutoFormat in a table (https://www.excelbanter.com/excel-programming/436205-need-excel-macro-turn-off-autoformat-table.html)

Jeremy

Need Excel macro to turn off AutoFormat in a table
 
I have data in an Excel 2007 table called "table2". I have a macro that
turns on the AutoFilters drop-down arrows in the table. It works fine in
Excel 2003 and 2007.

I have another macro that in Excel 2003 works fine to turn off the
AutoFilters in the table, but it doesn't work for Excel 2007. The macro that
works for Excel 2003 is:

Sub RemoveAutoFilters()
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.AutoFilterMode = False
End If
End Sub

What am I doing wrong that it won't work in Excel 2007? I have Bing/Googled
it but can't find the answer. Thank you!


Jeremy

Need Excel macro to turn off AutoFormat in a table
 
Sorry the title is wrong - I meant Excel macro to turm of AutoFilter in a
table. I will repost.

"Jeremy" wrote in message
...
I have data in an Excel 2007 table called "table2". I have a macro that
turns on the AutoFilters drop-down arrows in the table. It works fine in
Excel 2003 and 2007.

I have another macro that in Excel 2003 works fine to turn off the
AutoFilters in the table, but it doesn't work for Excel 2007. The macro
that works for Excel 2003 is:

Sub RemoveAutoFilters()
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.AutoFilterMode = False
End If
End Sub

What am I doing wrong that it won't work in Excel 2007? I have
Bing/Googled it but can't find the answer. Thank you!



OssieMac

Need Excel macro to turn off AutoFormat in a table
 
Hi Jeremy,

You need to reference the table in the worksheet not just the worksheet.
The "If/End If " is not required if you simply want to ensure AutoFilter is
Off.

Example 1:
Sub TablesAndAutoFilter()

Dim ws As Worksheet
Dim objList As ListObject

Set ws = ActiveWorkbook.Worksheets("Sheet1")

Set objList = ws.ListObjects("Table2")

If objList.ShowAutoFilter Then 'Omitted if simply turning off
objList.ShowAutoFilter = False
End If 'Omitted if simply turning off

End Sub


Example 2:
Without assigning to variables and simply ensuring that autofilter is off.

ActiveWorkbook.Worksheets("Sheet1") _
.ListObjects("Table2") _
.ShowAutoFilter = False


--
Regards,

OssieMac




All times are GMT +1. The time now is 10:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com