Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default passing array to functions byref

Hi i am new to excel programing can any body help me in knowing how to pass
an array to function byref. i need this very badly

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default passing array to functions byref

Sub main()

Dim a(5, 5)


y = PassArray(a)


End Sub

Function PassArray(ByRef a())

b = a(5, 1)
End Function


"kris" wrote:

Hi i am new to excel programing can any body help me in knowing how to pass
an array to function byref. i need this very badly

Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default passing array to functions byref

Joel has shown you the code.
However, as ByRef is the default in VB/VBA, you can omit it.
Also, if you try to change the function signature to ByVal instead, you will
get a compile error "Array argument must be ByRef".

So your array will always be byref anyway.

Note that if the array is in a Variant, then all the normal ByRef/ByVal
considerations apply. e.g.

Private Sub CommandButton1_Click()
Dim a(5, 5)

a(5, 1) = "Original"

PassArray (a)
Debug.Print a(5, 1)

PassArray a
Debug.Print a(5, 1)

End Sub

Function PassArray(ByRef a As Variant)
a(5, 1) = "New value"
End Function

NickHK

"kris" wrote in message
...
Hi i am new to excel programing can any body help me in knowing how to

pass
an array to function byref. i need this very badly

Thanks in advance




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default passing array to functions byref



"kris" wrote:

Hi i am new to excel programing can any body help me in knowing how to pass
an array to function byref. i need this very badly

Thanks in advance



Thanks again Joel and NickHK
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing range to function: type of argument is byref incompatible mcgurkle Excel Programming 3 May 7th 07 08:43 AM
Templates and passing functions Maistrye[_8_] Excel Programming 1 August 18th 06 09:56 PM
passing targets between functions ph8[_44_] Excel Programming 6 March 8th 06 03:16 PM
passing arrays between functions in VBA Tom Ogilvy Excel Programming 3 March 1st 04 05:54 PM
ByRef not passing address Ian Stanborough Excel Programming 3 October 30th 03 01:30 PM


All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"