LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Assigning a Range to a dynamic array

Hey guys,

I have a function that I would like to use to return an array of
ranges. It is important that the returned array however is dynamic as
I would then like to be able to use a loop to union the ranges
regardless of how many there are. Here is the code so far:

Public Function SelectSeries(SeriesColumnLetter) As Variant()

Sheets("Data").Select

Dim SeriesRange(1 To 4)
Dim DataSelection(1 To 4)
Dim DataSource() As Variant

Dim i

For i = 1 To 4

If SeriesColumnLetter(i) < " " Then

Set SeriesRange(i) = Worksheets("Data").Range(SeriesColumnLetter(i) &
"7:" & SeriesColumnLetter(i) & "65536")
DataNumber = Application.WorksheetFunction.CountA(SeriesRange(i ))
DataSelection(i) = SeriesColumnLetter(i) & "7:" &
SeriesColumnLetter(i) & (DataNumber + 6)

Set DataSource(i) = Worksheets("Data").Range(DataSelection(i))

Else

MsgBox ("No column letter!")

End If

Next

SelectSeries = DataSource()

End Function

Four SeriesColumnLetter variables are input into the function.Usually
these values are a letter, but sometimes they are blank. If they are
blank, I would like them to be excluded from the returning array i.e.
if 1 out of the 4 is blank, then the returning array would contain 3
values.

At the line:

Set DataSource(i) = Worksheets("Data").Range(DataSelection(i))

I get the error: 'Subscript out of range'. I guess this is because the
array has been declared dynamically. How can I get around this and
return a dynamic array??

Thanks and regards,

Tom
 
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
Assigning named range to a 2-dimensional array Bob Excel Programming 5 September 4th 07 11:28 AM
Assigning an array to range object? Smitch Excel Programming 2 February 16th 07 03:10 PM
assigning array back to range Jane Excel Programming 1 November 11th 04 07:45 AM
Assigning Range to Array Stratuser Excel Programming 3 October 30th 04 01:50 AM
Assigning range to array not working Marston Excel Programming 2 August 12th 04 11:38 PM


All times are GMT +1. The time now is 12:19 AM.

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"