+ Reply to Thread
Results 1 to 2 of 2

Returning value from Function

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-16-2011
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    405

    Question Returning value from Function

    Hi guys,

    Below is my function.
    I want to return to the sub routine the two values found from the funciton TRw & BRw
    How do i do this?

    Sub Test
    Function(iRow,iCol) 'Send these cell details to function Range - which should return the values of the Top Row and Bottom Row of the sent cell
    End Sub
    
    Function Range(Rw, Col)
    Dim i As Integer
    Dim TRw, BRw As Integer
    
    i = 0
    Do Until Cells(Rw + i, Col).Borders(xlEdgeTop).LineStyle = xlContinuous
    i = i + 1
    Loop
    TRw = Rw - i
    
    i = 0
    Do Until Cells(Rw - i, Col).Borders(xlEdgeBottom).LineStyle = xlContinuous
    i = i + 1
    Loop
    TRw = Rw + i
    
    End Function
    Regards
    Jordan

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Returning value from Function

    Hello jordan2322,

    You can not use the names "Function" and "Range" as either a Sub or Function call name. These are reserved words. When passing values, the default is ByRef. This means the value being passed must first have been declared and a value assigned to it. The other method is ByVal which passes the argument as it is.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1