![]() |
array functions
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. |
array functions
You need to add a
ReDim wkbk(j) statement somewhere between Dim wkbk() As String and the beginning of your For loop. Jerry R.VENKATARAMAN wrote: 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. |
array functions
thank you. shall try.
Jerry W. Lewis wrote in message ... You need to add a ReDim wkbk(j) statement somewhere between Dim wkbk() As String and the beginning of your For loop. Jerry R.VENKATARAMAN wrote: 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. |
All times are GMT +1. The time now is 05:07 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com