Redim Subscript Out Of Range Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more redim preserve subscript out of range vba about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users excel vba array transpose Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping
Vba Redim Preserve Multidimensional Array
each other. Join them; it only takes a minute: Sign up ReDim Preserve “Subscript Out of Range” up vote 2 down vote favorite I am trying to move data from 2 Double Arrays to 2 different Double Arrays.
Vba Transpose 2d Array
I'm not sure what the size is going to be because I am taking a randomized sample out of the first arrays and putting it into the 2nd arrays. When I add the ReDim Preserve line I get the Subscript Out of Range error. Function CreateTrainingSet(TrainingPercent As Double, Inputs() As Double, Outputs() As Double) ' Create Randomized Training set data Dim TrainingInputs() As Double, TrainingOutputs() As Double Dim i As Integer, j As Integer, count As Integer vba array subscript out of range 'ReDim TrainingInputs(UBound(Inputs, 1), UBound(Inputs, 2)) 'ReDim TrainingOutputs(UBound(Outputs, 1), UBound(Outputs, 2)) count = 0 ' Move TraningPercent % of data from Inputs and Outputs to TrainingInputs and TrainingOutputs For i = LBound(Inputs, 1) To UBound(Inputs, 1) Dim ran As Double ran = Rnd() If ran <= TrainingPercent Then count = count + 1 For j = LBound(Inputs, 2) To UBound(Inputs, 2) ReDim Preserve TrainingInputs(1 To count, 1 To UBound(Inputs, 2)) TrainingInputs(count, j) = Inputs(i, j) Next j For j = LBound(Outputs, 2) To UBound(Outputs, 2) ReDim Preserve TrainingOutputs(1 To count, 1 To UBound(Outputs, 2)) TrainingOutputs(count, j) = Outputs(i, j) Next j End If Next i For i = LBound(TrainingInputs, 1) To UBound(TrainingInputs, 1) For j = LBound(TrainingInputs, 2) To UBound(TrainingInputs, 2) Cells(i, j + 10).Value = TrainingInputs(i, j) Next j Next i End Function arrays excel vba excel-vba vb6 share|improve this question edited May 8 '14 at 5:48 Clara Onager 2,4411753 asked Apr 30 '14 at 16:13 atomant 26117 Do you get the error on the redim preserve line? –PowerUser Apr 30 '14 at 16:17 9 You can only redim the last dimension of a 2-D array when using Preserve. –Tim Williams Apr 30 '14 at 16:19 1 Tim's correct. You'll have to Redim a new array, without Preserve, and repopulate it every time. The good news is that there was wasn't much of performanc
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
Transpose Vba
policies of this site About Us Learn more about Stack Overflow the vba ubound company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users vba dynamic array Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes http://stackoverflow.com/questions/23393123/redim-preserve-subscript-out-of-range a minute: Sign up Redim Preserve gives 'subscript out of range' up vote 2 down vote favorite I want to Redim Preserve an array I keep getting the error 'subscript out of range'. I am aware of the fact that only the size of the last dimension can be changed. That is exactly what I am doing. What is going wrong over http://stackoverflow.com/questions/14055734/redim-preserve-gives-subscript-out-of-range here? The type of the array is Variant. BmMatrix = Sheets("BENCH").Range("a60", ActiveSheet.Range("a60").End(xlDown).End(xlToRight)) 'totaal gewicht per subdeel in array wegschrijven Dim aBmMatrix() aBmMatrix = BmMatrix rij = UBound(BmMatrix, 1) kol = UBound(BmMatrix, 2) + 1 ReDim Preserve aBmMatrix(rij, kol) TotGewKol = UBound(aBmMatrix, 2) For i = 2 To UBound(BmMatrix, 1) g = 0 'g wordt totaal gewicht van land bv If BmMatrix(i, bm_kolom) <> "x" Then For j = 2 To UBound(bmexnul, 1) If bmexnul(j, weightkolom) = BmMatrix(i, bm_kolom) Then g = g + bmexnul(j, 10) Next j End If aBmMatrix(i, TotGewKol) = g aBmMatrix(1, TotGewKol) = "Totaal gewicht" 'titel kolom Next i arrays vba excel-vba subroutine preserve share|improve this question edited Dec 27 '12 at 13:55 GSerg 48.1k1075128 asked Dec 27 '12 at 13:48 Amir 531311 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted Because you assign aBmMatrix array using the Value property of a range, the returned array has lower bounds of 1 for each dimension. When you later redim it without providing lower bounds explicitly, the redim tries to assign each dimension th
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Samples Retired content https://msdn.microsoft.com/en-us/library/aa264519(v=vs.60).aspx We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Reference Trappable Errors Core Visual Basic Language Errors Core Visual Basic Language Errors 9 Subscript out of range http://www.vbforums.com/showthread.php?691155-ReDim-Array-and-get-Subscript-Out-of-Range-problem 9 Subscript out of range 9 Subscript out of range 3 Return without GoSub 5 Invalid procedure call or argument 6 Overflow 7 Out of memory 9 Subscript out of range 10 This array subscript out is fixed or temporarily locked 11 Division by zero 13 Type mismatch 14 Out of string space 16 Expression too complex 17 Can't perform requested operation 18 User interrupt occurred 20 Resume without error 28 Out of stack space 35 Sub, Function, or Property not defined 47 Too many DLL application clients 48 Error in loading DLL 49 Bad DLL calling convention 51 Internal error 52 Bad subscript out of file name or number 53 Can't find specified file 54 Bad file mode 55 File already open 57 Device I\O error 58 File already exists 59 Bad record length 61 Disk full 62 Input past end of file 63 Bad record number 67 Too many files 68 Device unavailable 70 Permission denied 71 Disk not ready 74 Can't rename with different drive 75 Path\File access error 76 Path not found 91 Object variable or With block variable not set 92 For loop not initialized 93 Invalid pattern string 94 Invalid use of Null 96 Can't sink this object's events because it's already firing events... 97 Can't call Friend procedure on an object that isn't an instance of... 98 A property or method call cannot include a reference to a private ... 321 Invalid file format 322 Can't create necessary temporary file 400 Form already displayed; can't show modally 422 Property not found 429 ActiveX component can't create object or return reference to this... 430 Class doesn't support Automation 432 File name or class name not found during Automation operation 438 Object doesn't support this property or method 440 Automation error 442 Connection to type library or object library for remote p
of Range problem If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 7 of 7 Thread: ReDim Array and get Subscript Out of Range problem Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Sep 13th, 2012,03:06 PM #1 jmsrickland View Profile View Forum Posts Thread Starter PowerPoster Join Date Jan 2008 Posts 11,072 ReDim Array and get Subscript Out of Range problem Public Type ColorArray ColorTable() As Long End Type Dim MyColorArray() As ColorArray Then in code ReDim MyColorArray(1).ColorTable(256) For this I get Index out of Range error Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes. Reply With Quote Sep 13th, 2012,03:36 PM #2 Magic Ink View Profile View Forum Posts Fanatic Member Join Date Mar 2008 Posts 960 Re: ReDim Array and get Subscript Out of Range problem ColorTable() has to be Dimmed for each element of MyColorArray() as in a Form; Code: Private Type ColorArray ColorTable() As Long End Type Private Sub Command1_Click() Dim MyColorArray(1) As ColorArray ReDim MyColorArray(1).ColorTable(256) End Sub Reply With Quote Sep 13th, 2012,06:30 PM #3 jmsrickland View Profile View Forum Posts Thread Starter PowerPoster Join Date Jan 2008 Posts 11,072 Re: ReDim Array and get Subscript Out of Range problem But then how do I use MyColorArray(1).ColorTable(256) in some other sub? If Command1 initialize each occurance of the array it is not local to Command1 and unavailable in some other sub? Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary