Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Subscript out range error when redimensioning dynamic array



I am trying to move items between two listboxes and am using an array
to do it. Here is the code in question. I have no problem copying the
listbox contents to the dynamic arrays. The problem seems to be that
when one of the listboxes is empty and I copy it to my dynamic array
there is no problem -- however when I attempt to redim it I get a
subscript out of range (error '9') error. If the listbox has data when
I copy it to the dynamic array there is no problem -- what gives?


This is code in an Office 2003 macro for Excel.


Thanks much.


Dim source() As Variant
Dim destination() As Variant


Dim i As Integer
Dim j As Integer


ReDim Preserve source(0 To UBound(lstAvailableMSCs.Column, 1), 0)
ReDim Preserve destination(0 To UBound(lstAvailableMSCs.Column, 1),

0)


source = lstAvailableMSCs.Column
destination = lstSelectedMSCs.Column


For i = 0 To lstAvailableMSCs.ListCount - 1
If lstAvailableMSCs.Selected(i) Then
ReDim Preserve destination(0 To UBound(source, 1), 0 To
UBound(destination, 2) + 1)
' ReDim Preserve destination(0 To UBound(source, 1), 1)
For j = 0 To UBound(source, 1)
destination(j, UBound(destination, 2)) =
lstAvailableMSCs.Column(j, i)
Next j
Else
ReDim Preserve source(0 To UBound(source, 1), 0 To
UBound(source, 2) + 1)
For j = 0 To UBound(source, 1)
source(j, UBound(source, 2)) =
lstAvailableMSCs.Column(j, i)
Next j
End If
Next i


lstSelectedMSCs.Column = destination
lstAvailableMSCs.Column = source

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Subscript out range error when redimensioning dynamic array

Replying to my own post -- I see where I screwed up -- can't do UBound
on an uninitialized array.


Crazy Cat wrote:
I am trying to move items between two listboxes and am using an array
to do it. Here is the code in question. I have no problem copying the
listbox contents to the dynamic arrays. The problem seems to be that
when one of the listboxes is empty and I copy it to my dynamic array
there is no problem -- however when I attempt to redim it I get a
subscript out of range (error '9') error. If the listbox has data when
I copy it to the dynamic array there is no problem -- what gives?


This is code in an Office 2003 macro for Excel.


Thanks much.


Dim source() As Variant
Dim destination() As Variant


Dim i As Integer
Dim j As Integer


ReDim Preserve source(0 To UBound(lstAvailableMSCs.Column, 1), 0)
ReDim Preserve destination(0 To UBound(lstAvailableMSCs.Column, 1),

0)


source = lstAvailableMSCs.Column
destination = lstSelectedMSCs.Column


For i = 0 To lstAvailableMSCs.ListCount - 1
If lstAvailableMSCs.Selected(i) Then
ReDim Preserve destination(0 To UBound(source, 1), 0 To
UBound(destination, 2) + 1)
' ReDim Preserve destination(0 To UBound(source, 1), 1)
For j = 0 To UBound(source, 1)
destination(j, UBound(destination, 2)) =
lstAvailableMSCs.Column(j, i)
Next j
Else
ReDim Preserve source(0 To UBound(source, 1), 0 To
UBound(source, 2) + 1)
For j = 0 To UBound(source, 1)
source(j, UBound(source, 2)) =
lstAvailableMSCs.Column(j, i)
Next j
End If
Next i


lstSelectedMSCs.Column = destination
lstAvailableMSCs.Column = source


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
Error:Subscript out of range Jay Excel Discussion (Misc queries) 1 April 10th 08 10:25 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
array: subscript out of range rachel Excel Programming 9 November 9th 04 03:03 AM
Redim 2D Array Subscript Out Of Range Error lopsided[_10_] Excel Programming 6 February 11th 04 08:24 AM
Subscript Out of Range error in Array... Kevin Lyons Excel Programming 3 February 4th 04 06:17 PM


All times are GMT +1. The time now is 05:17 PM.

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"