+ Reply to Thread
Results 1 to 5 of 5

Passing a variable from a Procedure to a Function

  1. #1
    Registered User
    Join Date
    08-29-2013
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    7

    Passing a variable from a Procedure to a Function

    Hello,

    Sorry if my question is stupid
    Is it possible to pass a variable from a sub procedure to a function?

    Example:

    Sub Populate_Translation()
    Dim k As Integer
    For i = 0 To UBound(array_cust)
    k = 1
    CustType1 = Range("H" & i + 2).Value
    array_cust(i, 0) = IdSite(Range("M" & i + 2).Value)
    CustType2 = Range("H" & i + 3).Value
    If CustType2 = CustType1 Then
    k = k + 1
    End If
    Next i


    And function:

    Function IdSite(site As String) As Integer
    Dim s As String

    site = Left(site, InStr(6, site, Separator, vbTextCompare))

    If s = "Online" Then
    IdSite = ""
    Else
    IdSite = k
    End If

    End Function



    So, the question is how do I pass the k variable from procedure to function, so that the function IdSite would be calculated base on k value?


    Thank you!!!

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Passing a variable from a Procedure to a Function

    Please Login or Register  to view this content.
    but of course you may not return "" if your function type is Integer.

  3. #3
    Registered User
    Join Date
    08-29-2013
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Passing a variable from a Procedure to a Function

    I have tried this, but I receive error: Argument not optional when the function is called

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Passing a variable from a Procedure to a Function

    You must pass k to the function as well now:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-29-2013
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Passing a variable from a Procedure to a Function

    It worked!!! I was missing this part.
    Thank you, Izandol!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Trouble passing variable to another function
    By Jasmith in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-28-2011, 10:15 AM
  2. Passing Boolean Variable To A Function
    By Shama in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2008, 11:20 PM
  3. [SOLVED] Passing multiple strings to variable in Replace Function
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2006, 01:10 PM
  4. [SOLVED] Passing a Function name as a procedure argument
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-07-2005, 11:00 AM
  5. PASSING VARIABLE TO .xlT FILE FROM .xlA FILE (CONTAINS 'Auto_Open' PROCEDURE)
    By Chuckles123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-09-2005, 02:31 PM

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