Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Pass "array of strings" into a function??

I thought this would be easy to solve, but I am having trouble
finding information on how to define a VBA function (or sub)
that has an "array of strings" as an argument. Here is my
defintion so far:

Sub Sort_Array_of_Strings (ByRef Arr() As String)

' stuff in here

End Sub


Whenever I try passing an array of strings into this subroutine
I get a "type mismatch" type of error message.

Can anyone show me how to correctly pass an array of
strings into a function or sub? How do I define the function as well?

Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Pass "array of strings" into a function??

Can anyone show me how to correctly pass an array of strings
to a function or sub? How do I define the function as well?


Here is an example for you to study (the subroutine names should tell you
what you need to know)...

Sub SubWithArrayArgument(Arr() As String)
MsgBox "UpperBound = " & UBound(Arr) & vbLf & "Last element = " &
Arr(UBound(Arr))
End Sub

Sub CallSubWithArrayArgument()
Dim MyArr() As String
MyArr = Split("one,two,three,four", ",")
SubWithArrayArgument MyArr
End Sub

Just run the CallSubWithArrayArgument subroutine (which could be a macro if
need be). It will create the MyArr array inside itself and then pass it to
the SubWithArrayArgument subroutine which will display the index for the
last element in that passed in array and also the value in that last
element. Obviously, the setup and passing mechanism would be the same for
functions as well. Hope this helps.

Rick Rothstein (MVP - Excel)

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
Sorting a text strings but omitting preceding "A" or "The" Pablo Excel Worksheet Functions 2 December 15th 09 10:10 PM
=IF function, reference problem to "text strings" in Data Validati Jim D.[_2_] Excel Discussion (Misc queries) 2 July 17th 09 08:56 AM
How do I use "offset" function in "array formula"? hongguang Excel Discussion (Misc queries) 3 April 4th 07 12:04 AM
Listbox header inside VBA (Array("Head1", "Head2", ...) Alex St-Pierre Excel Programming 2 October 25th 06 09:28 PM
If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ... Maria J-son[_2_] Excel Programming 2 March 5th 06 12:20 PM


All times are GMT +1. The time now is 09:39 PM.

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

About Us

"It's about Microsoft Excel"