Functions - Help building RRS feed

  • Question

  • Good day, all-

    I have the following code used throughout my excel VBA, and I'd like to turn it into a function.

    SrcData = ActiveSheet.Name & "!" & Range("A3:J" & LastRow).Address(ReferenceStyle:=xlR1C1)

    I've built this function:

    Function SourceData(LastRow As Long) As Range
        SourceData = ActiveSheet.Name & "!" & Range("A3:P" & LastRow).Address(ReferenceStyle:=xlR1C1)
    End Function

    I'm using this to call the function:

    SrcData = SourceData(LastRow)

    However, when I run this, I get an error that says "object variable or With Block variable not set", and the error is on the code inside the function.

    Any help (or detail of what additional information is needed to help) is appreciated.



    • Edited by Casey_M Wednesday, September 2, 2015 3:58 PM
    Wednesday, September 2, 2015 3:56 PM


  • SourceData returns a string, not a range. So use

    Function SourceData(LastRow As Long) As String

    instead of

    Function SourceData(LastRow As Long) As Range

    Regards, Hans Vogelaar (

    Wednesday, September 2, 2015 5:37 PM