vba function parameter as range code example

Example 1: excel vba can a vba function return a range?

'VBA functions can return an Excel range, but since a range
'is an object, the 'Set' keyword is required:

Function Test() As Range
    Set Test = [A1:Z99]
End Function

Example 2: vba pass named range to function

Private Sub copyABU()
   Call copyPaste(ThisWorkbook.Names("myRange1").RefersToRange)
   Call copyPaste(ThisWorkbook.Names("myRange2").RefersToRange)
   Call copyPaste(ThisWorkbook.Names("myRange3").RefersToRange)
   ' //etc
End Sub

Tags:

Vb Example