+ Reply to Thread
Results 1 to 7 of 7

3d array

Hybrid View

brucemc777 3d array 04-30-2016, 02:45 PM
MrShorty Re: 3d array 04-30-2016, 03:19 PM
shg Re: 3d array 04-30-2016, 03:23 PM
brucemc777 Re: 3d array 04-30-2016, 03:57 PM
shg Re: 3d array 04-30-2016, 04:10 PM
brucemc777 Re: 3d array 04-30-2016, 05:30 PM
shg Re: 3d array 04-30-2016, 05:57 PM
  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    615

    3d array

    I am attempting to read (designated/marked pairs of string values) from a number of (tables on one sheet) into an array.

    The number of tables on the sheet changes over time.

    The number of rows in each table changes over time.

    The number of columns in each table is fixed at two, and when the first of the two columns is marked the items in that row constitute the pair of values.

    The marker for the information from the cells that I want read into the array from each table is that the first cell in each needed row will have a comment created/attached to it.

    Everything in the following blows up (fails) at the point: arReport(intTblCtr) = tbl.name

    tbl.Name is correct, but obviously my handling of assigning values to an array isn't.

    I have more explanation of what I intend to do in the comments of the following code.

    I am probably mis-using the word "parameter" in my attempt to describe the three "positions" (labeled immediately hereafter: "A", "B" and "C": array(A,B,C) ) within the entire array.

    Sub FUHistoryReport()
    Dim intCtr As Integer
    Dim intTblCtr As Integer
    Dim intRowCtr As Integer
    Dim arReport() As String
    Dim tbl As ListObject
    
    
        intTblCtr = 0
        intRowCtr = 0
        For Each tbl In Worksheets("FUHistory").ListObjects
            intTblCtr = intTblCtr + 1
            If tbl.DataBodyRange.Rows.Count > intRowCtr Then intRowCtr = tbl.DataBodyRange.Rows.Count
        Next tbl
        
        ReDim arReport(1 To intTblCtr, 1 To intRowCtr, 1 To 2) As String
        
        intTblCtr = 0
        intRowCtr = 0
        For Each tbl In ActiveSheet.ListObjects
            intTblCtr = intTblCtr + 1
            arReport(intTblCtr) = tbl.Name 'For each Table I want to assign the name of the table to the array's first parameter
            For intRowCtr = 1 To tbl.DataBodyRange.Rows.Count
                arReport(intTblCtr, intRowCtr) = tbl.DataBodyRange.Row 'For each row number in the Table being read in, I want to
                                                                        'assign the row number (of the databodyrange) into the second
                                                                        'array parameter
                If Not tbl.DataBodyRange.Cells(intRowCtr, 1).Comment Is Nothing Then 'And each time the first column's cell has a comment,
                                                                                  'I want to assign the first column's value to the first
                                                                                  'of the third parameter's items and the second column
                                                                                  'to the second of the third column's parameters...
                    arReport(intTblCtr, intRowCtr, 1) = tbl.DataBodyRange.Cells(intRowCtr, 1).Text
                    arReport(intTblCtr, intRowCtr, 2) = tbl.DataBodyRange.Cells(intRowCtr, 2).Text
                End If
            Next intRowCtr
        Next tbl
        Stop
    End Sub
    Help?!?

    I did my best to break everything down for I know sometimes I post requests with presumed knowledge of what I am trying to do swimming around in my head!

    Thank-you!
    Last edited by brucemc777; 04-30-2016 at 03:48 PM. Reason: ReDim line of code, now using "1 to"

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,361

    Re: 3d array

    A sample spreadsheet so we can see the data in the spreadsheet will likely be very helpful in visualizing what you are wanting to go into what element of the array.

    Note that this syntax:
    arReport(intTblCtr) = tbl.Name
    'or 
    arReport(intTblCtr, intRowCtr) = tbl.DataBodyRange.Row
    is invalid. arReport is a 3D array, so any assignment statement must reference a single element using all three indices. It is not clear to me exactly where in the array you want to store these pieces of information, but your assignment statement must refer to a single element:
    arReport(intTblCtr,0,0)=tbl.Name
    or
    arReport(intTblCtr,intRowCtr,0)=tbl.DataBodyRange.Row
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 3d array

    arReport(intTblCtr) = tbl.Name 'For each Table I want to assign the name of the table to the array's first parameter
    
    arReport(intTblCtr, intRowCtr) =
    When you index a 3D array, you need three indices.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    615

    Re: 3d array

    Much appreciated (btw, I previously lived in Cedar Park, TX... )

    From what you wrote I found my concept of a multidimensional array flawed and with additional study figured out something that functions. I don't know how optimized it is (...), but:

    Sub FUHistoryReport02()
    Dim intCtr As Integer
    Dim intTblCtr As Integer
    Dim intRowCtr As Integer
    Dim arReport() As String
    Dim tbl As ListObject
    
    
        intTblCtr = 0
        intRowCtr = 0
        For Each tbl In Worksheets("FUHistory").ListObjects
            intTblCtr = intTblCtr + 1
            If tbl.DataBodyRange.Rows.Count > intRowCtr Then intRowCtr = tbl.DataBodyRange.Rows.Count
        Next tbl
        
        ReDim arReport(1 To intTblCtr, 1 To intRowCtr, 1 To 2, 1 To 3) As String
        
        intTblCtr = 0
        intRowCtr = 0
        For Each tbl In ActiveSheet.ListObjects
            intTblCtr = intTblCtr + 1
            For intRowCtr = 1 To tbl.DataBodyRange.Rows.Count
                If Not tbl.DataBodyRange.Cells(intRowCtr, 1).Comment Is Nothing Then
                    arReport(intTblCtr, intRowCtr, 1, 1) = tbl.Name
                    arReport(intTblCtr, intRowCtr, 1, 2) = CStr(intRowCtr)
                    arReport(intTblCtr, intRowCtr, 1, 3) = tbl.DataBodyRange.Cells(intRowCtr, 1).Text
                    arReport(intTblCtr, intRowCtr, 2, 1) = tbl.Name
                    arReport(intTblCtr, intRowCtr, 2, 2) = CStr(intRowCtr)
                    arReport(intTblCtr, intRowCtr, 2, 3) = tbl.DataBodyRange.Cells(intRowCtr, 2).Text
                End If
            Next intRowCtr
        Next tbl
        Stop
    End Sub
    How's it look to you?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 3d array

    The second dimension of the array will only be as large as the number of rows in the last table.

  6. #6
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    615

    Re: 3d array

    It is my intention that intRowCtr should only be overwritten if the present evaluated table's row count is greater than its value; have I done something wrong?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 3d array

    Ah, missed that.

    So, does it all work?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 04-02-2016, 08:16 PM
  2. [SOLVED] Populate one array from another array and print new array as a range
    By Kaden265 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2014, 07:52 AM
  3. Loop new messages containing a table, populate a dynamic array, paste array to Excel
    By laripa in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2013, 07:20 AM
  4. [SOLVED] Quick Array question - Copy array to another array then resize?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2013, 01:17 AM
  5. [SOLVED] Populate Listbox with all rows of a dynamic array where elements of a single array match.
    By Tayque_J_Holmes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2012, 04:54 AM
  6. Single Conditional Array x two Multi-Column Array - Approach needed
    By David Brown in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-28-2010, 11:41 AM

Tags for this Thread

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