Wednesday, September 17, 2014

Excel Macro to apply data filter, autosize cols etc

I've been working with a lot of hadoop output files lately and inspecting the top results with Excel.

Consequently this is a useful Excel macro to prepare the data for browsing - Applies data filter for sorting, bold headings, freeze top row, autosize columns.

Good to map it to Ctrl + Shift + D as well.


Sub ApplyDataFilter()
'
' Excel 2013 ApplyDataFilter Macro
' Applies data filter, bold headings, freeze top row, autosize columns.
'
    Rows("1:1").Select
    Selection.Font.Bold = True
    With ActiveWindow
        .SplitColumn = 0
        .SplitRow = 1
    End With
    ActiveWindow.FreezePanes = True
    Cells.Select
    Selection.AutoFilter
    Range("A2").Select
   
    Cells.Select
    Cells.EntireColumn.AutoFit
End Sub