Mysteriously, according to how i am reading this code....
This code works perfectly the first time I apply it to a workbook on all sheets.
But, when i add columns to various sheets, then run the code again, the row1 AutoFilter is NOT APPLYING to the additional columns. The original columns autofilter is still there.
There are no blank cells in row 1 (contiguous cells with text)
I assumed.... (Rows"1:1" should be all columns in row 1?, provided there are no blank cells seperating non blank cells in row1?)
But, the 'autofit' IS APPLIED to the new columns.
is this....... "If Not ws.AutoFilterMode"..............somehow causing it to not operate as i would like?
I don't see how the 2nd application would be different from the 1st.
This code works perfectly the first time I apply it to a workbook on all sheets.
But, when i add columns to various sheets, then run the code again, the row1 AutoFilter is NOT APPLYING to the additional columns. The original columns autofilter is still there.
There are no blank cells in row 1 (contiguous cells with text)
I assumed.... (Rows"1:1" should be all columns in row 1?, provided there are no blank cells seperating non blank cells in row1?)
But, the 'autofit' IS APPLIED to the new columns.
is this....... "If Not ws.AutoFilterMode"..............somehow causing it to not operate as i would like?
I don't see how the 2nd application would be different from the 1st.
VBA Code:
Option Explicit
Sub filterfreezautofit()
'filterfreezautofit
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
If Not ws.AutoFilterMode Then ws.Rows("1:1").AutoFilter
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
Cells.EntireColumn.autofit
Next ws
End Sub