Monday, October 28, 2013

Dynamic Filtering


Dim filterValues() As String

'add all required values to the filter
'actvate the sheet that has filter
'you can use a dynamic range and filter column as well
'Field corresponds to column used to filter

ActiveSheet.Range("$A$1:$Z$6000").AutoFilter Field:=6,_
 Criteria1:=filterValues, Operator:=xlFilterValues

Friday, October 4, 2013

Handy Functions for Tables (ListObject)

Functions to get row number or column number for an active cell selected in the table

Function GetActiveCellTableRowNum() As Long
    Dim currTable As ListObject
    Set currTable = ActiveCell.ListObject
    
    If currTable Is Nothing Then
        GetActiveCellTableRowNum = -1
    Else
        GetActiveCellTableRowNum = _ 
            ActiveCell.Row - currTable.HeaderRowRange.Row
    End If
End Function


Function GetActiveCellTableColNum() As Long
    Dim currTable As ListObject
    Set currTable = ActiveCell.ListObject
    
    If currTable Is Nothing Then
        GetActiveCellTableColNum = -1
    Else
        GetActiveCellTableColNum = _
           currTable.ListColumns(ActiveCell.Column - _
           currTable.HeaderRowRange.Cells(1).Column + 1).Index
    End If
End Function