Consulting

Results 1 to 5 of 5

Thread: Passing a value to another sub routine

  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Posts
    34
    Location

    Passing a value to another sub routine

    Ok I am seeming to have many problems today

    I am trying to pass a cell value to another subroutine. Does any one have any idea as to how to declare this and pass it to the next routine to use

    here is the first code
    [VBA]If rBLoopCells.Value > 0 Then
    With rBLoopCells
    ActiveCell.Select
    .Offset(-1, 0).Select
    ActiveCell.Select

    YrVal = ActiveCell.Value
    ResetFound
    Call ResetFound[/VBA]

    Ok so the YrVal is the value i want to pass to the ResetFound routine to use it this way

    [VBA]If rBLoopCells.Value > 0 Then
    With rBLoopCells
    ActiveCell.Select
    .Offset(-1, 0).Select
    ActiveCell.Select

    YrVal = ActiveCell.Value
    ResetFound
    Call ResetFound[/VBA]

    Any Ideas????

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    You can declare a public variable at the top of the module, or pass the variable as an argument to your second subroutine. Something like[VBA]Sub SecondSubRoutine(YrVal as Long)
    'code
    End Sub[/VBA]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why do you have a ResetFound and a Call ResetFound routine?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Your code is very confused. You can set the variable without selecting any cells. Something like
    [VBA]Sub Test()
    Dim rBLoopCells As Range, YrVal
    Set rBLoopCells = Range("C10")
    If rBLoopCells.Value > 0 Then
    YrVal = ActiveCell.Offset(-1)
    ResetFound YrVal
    End If
    End Sub

    Private Sub ResetFound(Data)
    MsgBox Data
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Well,you can pass value to a subroutine using the syntax
    1.For declaration of subroutine
    Private sub subroutinename(<variable> as <datatype>)
    ////statements/////
    End Sub
    2.For calling
    Subroutinename <variable>
    Hope this helps….
    Chris
    ------



Posting Permissions

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