+ Reply to Thread
Results 1 to 3 of 3

using cell content to identify range + array?

  1. #1
    Registered User
    Join Date
    05-24-2004
    Posts
    52

    using cell content to identify range + array?

    Hi,

    I need help with something that I should probably know but can't seem to remember how to solve. I've got a piece of code that uses a For/Next loop to calculate the value of an object 'Total' based on values in various arrays:

    Please Login or Register  to view this content.
    And the code works great except that I'd like to be able to change the upper bound of R and the ArrA & ArrB array sizes based on the value in a worksheet cell (rather than having to change the coding each time that cell value changes). I know I can assign an object name to the cell's value (="Max") & can then say "For R = 1 to Max", but how to I use "Max+1" to describe the upper bounds of my two arrays so that R will loop through all the array entries & doesn't stop short or over-shoot the size of each array?? And how can I do that without having to use additional loops to define my two arrays?

    I've been playing arround with solutions like:
    Please Login or Register  to view this content.
    But nothing has worked so far. And, since it's been a nearly a year since I wrote code, I can't remember if I can actually use UBound to define an array (or if I can only use it to loop through entries in the array) or if there's a better solution that I just haven't though of yet.

    Can anyone help jog my memory and suggest a quick & easy solution?
    I'd be very grateful for any help you can give!
    Thx.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    On the right track.

    1) Don't use reserved words as variables. So instead of MAX, use something like myMAX or Ulim...

    2) Set the array in the way you have mentioned

    myMax = WB.Worksheets("Table").Range("N8").Value +1
    ArrA = WB.Worksheets("Table").Range("K2:K" & myMax).Value

    3) As long as both arrays are going to be the same size, then use the lbound and ubound to get the dimensions

    for R = lbound(arra) to ubound(arra)
    ...
    next R


    hth

    rylo

  3. #3
    Registered User
    Join Date
    05-24-2004
    Posts
    52

    Smile Thx!

    Thanks so much rylo. That worked like a charm!
    I'm really grateful!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1