Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Subscript out of Range Error

The problem stems from the dimensioning of the array.

On your first redim to set it to 1 elementwhich is in fact to elements 0 and
1.

On your second redim you tried to change the lower bound which you are not
allowed to do.

You can either

set option base 1

or you can

ReDim FullSheetNames(1 to 1) As String

As an aside you can improve your code because you cannot have a sheetname
="" thats unless somebody nows differently:

Sub FillArray()
Dim i As Integer
Dim FullSheetNames() As String
ReDim FullSheetNames(1 To ThisWorkbook.Worksheets.Count) As String
For i = 1 To ThisWorkbook.Worksheets.Count
FullSheetNames(i) = ThisWorkbook.Worksheets(i).Name
Next i
End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"BOBODD" wrote:

The sub below runs into a "Subscript out of Range" error when it gets to
ReDim Preserve FullSheetNames(1 To i) As String.

There is a case select at the beginning of this sub that vets some of the
sheets, but it isn't relevant to this error. Can anyone tell me what I'm
missing?

Private Sub FillArray()
Dim i As Integer
Dim wks As WorkSheet
Dim SheetNames As String
Dim FullSheetNames() As String
For Each wks In ThisWorkbook.Worksheets
If SheetNames < "" And i 1 Then
ReDim Preserve FullSheetNames(1 To i) As String
FullSheetNames(i) = SheetNames
i = i + 1
ElseIf SheetNames < "" And i = 1 Then
ReDim FullSheetNames(1) As String
FullSheetNames(1) = SheetNames
i = i + 1
End If
Next
End Sub

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
Runtime Error - Subscript out of range despite On Error statement DoctorG Excel Programming 3 July 28th 06 03:56 PM
Subscript out of range error - save copy error bg18461[_16_] Excel Programming 2 June 13th 06 04:53 PM
Subscript out of range error - save copy error bg18461[_15_] Excel Programming 1 June 13th 06 04:36 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
Help on subscript out of range error (VB6/VBA) farmer[_2_] Excel Programming 2 November 2nd 03 04:19 PM


All times are GMT +1. The time now is 11:30 AM.

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

About Us

"It's about Microsoft Excel"