XLA Routines: EE_FormatCols

Nick's picture
Useful routine for formatting columns from an imported file
Sub EE_FormatCols(rngSource As Range, Optional rngTarget As Range)
'http://excelexperts.com/xla-routines-eeFormatCols    for updates on this sub routine
' takes a source range containing the heading and format in 2 cols
' looks in the target range and formats the target range
Dim rngHd As Range
Dim rngFound As Range
 
    Call EE_Start
 
    Set rngTarget = EE_TableDefault(rngTarget).Rows(1)
    For Each rngHd In rngSource.Rows
        Set rngFound = rngTarget.Find(rngHd.Cells(1).value, , xlValues, xlWhole)
        If Not rngFound Is Nothing Then
            rngHd.Cells(, 2).Copy
            rngFound.Parent.Columns(rngFound.Column).EntireColumn.PasteSpecial xlPasteFormats
            rngHd.Cells(1).Copy
            rngFound.PasteSpecial xlPasteFormats
 
        End If
    Next
    Call EE_End
End Sub