array functions

R

R.VENKATARAMAN

extract of my code

Dim i As Integer
Dim j As Integer
Dim sh As Worksheet
Set sh = ThisWorkbook.Worksheets("sheet2")
Dim mysectors As Range
Dim sector1 As Range
Dim sectorlast As Range
Set sector1 = sh.Range("c2")
Set sectorlast = sh.Range("c2").End(xlDown)
Set mysectors = Range(sector1, sectorlast)
j = WorksheetFunction.CountA(mysectors)
MsgBox j
Dim wkbk() As String****************
Dim mypath As String
mypath = "e:\temporary\choksey\choksey 18-10\"
For i = 1 To j
wkbk(i) = mypath & Sheet2.Range("c2").Offset(i - 1, 0) & ".xls"

with this code when I come to the last statement error "subscript out of
range" comes
But if amend the stament marked *******as <dim wkbk(16) as string>
it works.
My problem is the the array dimension changes.
instead of having wkbk() as dynamic aarray can I give a larger value for
dimension for e.g
wkbk(50) and use only 15 or 16 or 20 wkbk()
or any other soluton
thanks and regards.
 
J

Jerry W. Lewis

You need to add a
ReDim wkbk(j)
statement somewhere between
Dim wkbk() As String
and the beginning of your For loop.

Jerry
 
R

R.VENKATARAMAN

thank you. shall try.


Jerry W. Lewis said:
You need to add a
ReDim wkbk(j)
statement somewhere between
Dim wkbk() As String
and the beginning of your For loop.

Jerry
 

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