Passing values to an array

T

T2B

Can I pass values (e.g. a concatenated string of days) to an array
from another function?

This sub works:

Sub xArray1()

Dim MyWeek, MyDay

MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")

For Each MyDay In MyWeek
Debug.Print MyDay
Next MyDay

End Sub

How could I make something like this work?

Sub xArray2(MyWeekValues as Variant)

Dim MyWeek, MyDay

MyWeek = Array(MyWeekValues)

For Each MyDay In MyWeek
Debug.Print MyDay
Next MyDay

End Sub
 
A

Allen Browne

The ParamArray keyword lets you pass an unspecified number of arguments to a
procedure. There's an example in the code on this page:
http://allenbrowne.com/ser-56.html

A variant can be an array, so you can pass a variant array in the way you
declared your sub, i.e. you could cal:
Call xArray2(MyWeek)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top