XLA routines: EE_Copy

Nick's picture
EE_Copy is one of the most used EE sub routines. Specify the source, and the top left of the target, and EE_Copy will copy the data over. Optionals to debug (go to each range), and transpose, or copy formatting too.
Sub EE_Copy(rngSource As range, rngTopLeftTarget As range, Optional blnCopyValues As Boolean = True, Optional blnCopyFormatting As Boolean = True, Optional blnTranspose As Boolean = False, Optional blnDebug As Boolean = False)
'Function EE_Copy()
'- takes source range
'- target range (top left cell only)
'
'Optional:
'- boolean copyValues
'- boolean copyFormatting
'- boolean Transpose
'- boolean Debug
'
'- default to copy values and formatting, no transpose or debug
'
'- if debug set to true, 3 messageboxes are displayed:
'  - 1 showing the source range
'  - 1 showing the target range as it is now
'  - 1 showing the target range after it has been copied over
'  - source and target range cell interiors are coloured green

'http://excelexperts.com/xla-routines-eeCopy    for updates on this sub routine

    If blnDebug Then
        Application.GoTo rngSource
        MsgBox "Source range", vbInformation
    End If
    rngSource.Copy
    If blnDebug Then
        Application.GoTo rngTopLeftTarget
        MsgBox "Target range before paste.", vbInformation
    End If
    If blnCopyValues Then
        rngTopLeftTarget.PasteSpecial Paste:=xlPasteValues, Transpose:=blnTranspose
    Else
        rngTopLeftTarget.PasteSpecial Paste:=xlPasteFormulas, Transpose:=blnTranspose
    End If
    If blnCopyFormatting Then
        rngTopLeftTarget.PasteSpecial Paste:=xlPasteFormats, Transpose:=blnTranspose
    End If
    If blnDebug Then
        Application.GoTo rngTopLeftTarget
        MsgBox "Target range after paste.", vbInformation
    End If
    Application.CutCopyMode = False
End Sub