PDA

View Full Version : Passing a value to another sub routine



viomman
03-04-2009, 09:48 AM
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
If rBLoopCells.Value > 0 Then
With rBLoopCells
ActiveCell.Select
.Offset(-1, 0).Select
ActiveCell.Select

YrVal = ActiveCell.Value
ResetFound
Call ResetFound

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

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

YrVal = ActiveCell.Value
ResetFound
Call ResetFound

Any Ideas????

nst1107
03-04-2009, 09:50 AM
You can declare a public variable at the top of the module, or pass the variable as an argument to your second subroutine. Something likeSub SecondSubRoutine(YrVal as Long)
'code
End Sub

Bob Phillips
03-04-2009, 10:26 AM
Why do you have a ResetFound and a Call ResetFound routine?

mdmackillop
03-04-2009, 02:09 PM
Your code is very confused. You can set the variable without selecting any cells. Something like
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

Chris Bode
03-05-2009, 12:27 AM
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….