+ Reply to Thread
Results 1 to 7 of 7

Populating a multi-dimensional array

  1. #1
    Registered User
    Join Date
    11-23-2007
    Posts
    65

    Populating a multi-dimensional array

    Hi guys,

    Firstly let me point out that my programming skill is pretty basic so I may have made some rookie mistakes in my code below.

    I have a spreadsheet which I will be adding to over time. I need a macro that will look for the last 10 rows and then pull together a summary table based on data from several of the columns on each of those rows.

    I've tried to go about this by using an array. The array will always be the same size (it will always be 10 by 11, i.e. EngineArray(10,11)-basically the same size as my summary table). I've also set Option Base 1.

    What I’ve got so far is below. It isn’t working properly though. To start with I was getting ‘type mismatch errors’. Now instead of reading the numbers from the selected cells into the array, it just changes all the cells I’m trying to read from to ‘TRUE’????!

    Can anyone point out what I’ve done wrong? Like I said, I’m pretty new to all this so I’m sure it’s probably something trivial. I’ve not included the pasting part of the macro because I think it’s the part below which is causing the problems.

    Please Login or Register  to view this content.
    Thanks in advance,

    Chris
    Last edited by VBA Noob; 11-28-2008 at 03:23 PM. Reason: Code tags added

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    Please remember to use code tags in future when posting code examples.


    It would help if you posted a workbook with example data.
    And explained what you intend to do with the contents of EngineArray


    for information this is what is causing your TRUE overwrite problem
    Please Login or Register  to view this content.
    First the Select method is performed and the the result of the implied test "Is the Active cell selected" is performed. By definition the activecell is selected so TRUE is written in to the cell.
    You probably meant to just set the active cell, in which case this would do it

    Please Login or Register  to view this content.
    But selecting cells is not required.

    Maybe, using loops, something like this.
    It will populate the array as the data is shown on the sheet.
    Please Login or Register  to view this content.
    Last edited by shg; 11-26-2008 at 10:16 AM.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-23-2007
    Posts
    65
    Thanks Andy!

    The only part of this I don't really understand is the following:

    Please Login or Register  to view this content.
    I think I get the split part of it, but I'm not sure what you're actually saying with the second part, in particular the code you've used after 'Range'. Could you quickly clarify?

    Thanks again!

    Chris

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    That section of code creates an array that contains the column numbers of the ranges that you want to lift data from.

    I could have used explicit values but I think this way is easier to relate to the worksheet, assuming you are using A1 notation. Basically those are the columns that contain the data you want.

  5. #5
    Registered User
    Join Date
    11-23-2007
    Posts
    65
    Thanks Andy - This works very well!

    Since using this method I've noticed something else. There is a chance that some of the rows in the spreadsheet are going to be blank. At the moment the code looks for the bottom row with something in it and then populates the array with data from that row and the previous 9 rows. Like I say though, some of these may be blank. Can this code be simply modified in some way so that it will fill the array with data from the last 9 rows with data in them??

    Sorry to be a pain - I only noticed this after implementing the above code.

    Thanks again!

    Chris

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    Try this,

    Start at bottom and works up. Only checks column F for empty cells

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-23-2007
    Posts
    65
    Excellent - works well! Thanks again!

+ 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