View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Melanie Breden Melanie Breden is offline
external usenet poster
 
Posts: 88
Default Excel VBA Function Parameter Overwritten

I have two vba functions in an excel macro, where the result of the
first is passed into the other as a parameter. The problem is that the
value of this paramter appears to be changed by the actions of this
second function, hence overwritting the value of my first functions
result. To illustrate:


perhaps the following helps you:

Sub CallFunc()
Dim a As Integer, b As Integer

MsgBox a & vbCr & b
a = funcone(0, "Hello")
MsgBox a & vbCr & b
b = functwo(a, "Hello")
MsgBox a & vbCr & b
End Sub

Function funcone(ByVal pos As Integer, text As String) As Integer
funcone = pos
End Function

Function functwo(ByVal pos As Integer, text As String) As Integer
For pos = 1 To 10
'Some tasks
Next pos
functwo = pos + 30
End Function

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)