+ Reply to Thread
Results 1 to 4 of 4

Pass sub variable to function

Hybrid View

ledzepe Pass sub variable to function 12-06-2006, 01:46 PM
Bryan Hessey Hi, Sub test() testme... 12-06-2006, 03:13 PM
ledzepe How about passing two... 12-06-2006, 03:36 PM
Bryan Hessey Hi, as Sub test() myvar... 12-06-2006, 03:44 PM
  1. #1
    Registered User
    Join Date
    07-13-2005
    Posts
    89

    Pass sub variable to function

    Hi and thanks in advance for any help.

    How can I pass a variable from a sub to a function? My codes are below:

    Sub Main()
    Dim Source, Dest
    Source = Z24
    Dest = T28
    SpecialFunc
    bla, bla, bla....
    End Sub

    Function SpecialFunc()
    Range(Source).Select
    bla, bla, bla....
    End Function

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by ledzepe
    Hi and thanks in advance for any help.

    How can I pass a variable from a sub to a function? My codes are below:

    Sub Main()
    Dim Source, Dest
    Source = Z24
    Dest = T28
    SpecialFunc
    bla, bla, bla....
    End Sub

    Function SpecialFunc()
    Range(Source).Select
    bla, bla, bla....
    End Function
    Hi,

    Sub test()
    testme ("test")
    End Sub
    
    Function testme(mytest As String)
    MsgBox mytest
    End Function
    should help you.

    ---
    Si fractum non sit, noli id reficere.

  3. #3
    Registered User
    Join Date
    07-13-2005
    Posts
    89
    How about passing two variables from a sub to a function? As in my earlier example:

    Sub Main()
    Dim Source, Dest
    Source = Z24
    Dest = T28
    SpecialFunc
    bla, bla, bla....
    End Sub

    Function SpecialFunc()
    Range(Source).Select
    Range(Dest).Select
    bla, bla, bla....
    End Function

    What I'm trying to accomplish is copying a cell to another cell. The cell positions move that is why I need to pass cell (source and destination) address variable to the function. If there's a better way, please tell me.

  4. #4
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by ledzepe
    How about passing two variables from a sub to a function? As in my earlier example:

    Sub Main()
    Dim Source, Dest
    Source = Z24
    Dest = T28
    SpecialFunc
    bla, bla, bla....
    End Sub

    Function SpecialFunc()
    Range(Source).Select
    Range(Dest).Select
    bla, bla, bla....
    End Function

    What I'm trying to accomplish is copying a cell to another cell. The cell positions move that is why I need to pass cell (source and destination) address variable to the function. If there's a better way, please tell me.
    Hi,

    as
    Sub test()
    myvar = "testing"
    testme ("test"), "Test2", "test3", myvar
    End Sub
    
    Function testme(mytest As String, mytest2 As String, mytest3 As String, myvar)
    MsgBox mytest & myvar
    End Function
    hth
    ---

    btw, your earlier sub may have set two variables, but the Function only indicated using one of them.
    ---
    Last edited by Bryan Hessey; 12-06-2006 at 03:50 PM.

+ 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