Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 21st, 2004, 07:08 AM
Registered User
Join Date: Nov 2004
Location: , , .
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


    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)


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)

j = j + 1
Loop Until j = 4

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

Reply With Quote
  #2 (permalink)  
Old November 23rd, 2004, 12:54 PM
Authorized User
Join Date: Oct 2004
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shattered Send a message via Yahoo to shattered

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)).

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:21 PM.

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