Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2004, 07:08 AM
Registered User
 
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Two dimensional array with run time error

I have tried to run the VBA, but there was a run time error "subscript out of range"
k(0) = 5
k(1) = 6
k(2) = 7
k(3) = 5
l(0) = 8
l(1) = 9
l(2) = 5
l(3) = 6

Do

    For j = 0 To 3

        ReDim feasible(k(4), 4)

        For i = 0 To k(j) - 1
        feasible(i, j) = Sheet1.Cells(3, 2 + j ) + i * (1 / 24) (subscript out of range)
    Next

    Next

For j = 0 To 3

    ReDim lunch(l(4), k(4), 4)
    For z = 0 To k(j) - 1
        For y = 0 To l(j) - 1
        lunch(y, z, j) = feasible(z, j) + Sheet1.Cells(5, 2 + j) + y * (1 / 24)

        Next
    Next
Next
j = j + 1
Loop Until j = 4

I would like to ask how can I run this coding appropriately

 
Old November 23rd, 2004, 12:54 PM
Authorized User
 
Join Date: Oct 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shattered Send a message via Yahoo to shattered
Default

looking at the code there could be any number of reasons. The most likely however is that you have only given a value to the first 4 elements of array K, yet when you redim the array feasible you use the 5th element of array k (which is empty).

So, when you try to write to feasible(1,0) it throws out the error (it does actually process feasible(0,0)).












Similar Threads
Thread Thread Starter Forum Replies Last Post
using 2 dimensional array Abraham EJB 0 July 17th, 2007 09:27 AM
two-dimensional array Lizane Java Basics 4 May 23rd, 2007 09:35 AM
2 dimensional array trangd Beginning PHP 0 August 18th, 2005 12:37 AM
2 dimensional array venterjo General .NET 2 January 23rd, 2005 09:04 AM
Searching a two dimensional array Dinesh22 VB.NET 2002/2003 Basics 1 January 13th, 2004 03:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.