Results 1 to 7 of 7

Need help on Basic Two Dimensional Dynamic Array

Threaded View

chrixton Need help on Basic Two... 03-02-2014, 10:59 AM
alvin-chung Re: Need help on Basic Two... 03-02-2014, 01:12 PM
Bernie Deitrick Re: Need help on Basic Two... 03-02-2014, 01:13 PM
TMS Re: Need help on Basic Two... 03-02-2014, 01:25 PM
chrixton Re: Need help on Basic Two... 03-02-2014, 01:59 PM
TMS Re: Need help on Basic Two... 03-02-2014, 02:40 PM
alvin-chung Re: Need help on Basic Two... 03-02-2014, 08:07 PM
  1. #1
    Registered User
    Join Date
    02-13-2014
    Location
    Boston, United States
    MS-Off Ver
    Excel 2010
    Posts
    12

    Need help on Basic Two Dimensional Dynamic Array

    Hello,

    I am new to VBA. I have managed to write the following code:

    Sub Testing()
    
    Dim Array(8 To 37, 3 To 23) As Long
    
    Dim i As Integer, j As Integer
    
    For i = 8 To 37
    
       For j = 3 To 23
       Array(i, j) = Cells(i, j)
       If Array(i, j) > 0 Then
       Cells(i, 2).Value = Cells(6, j).Value
       Exit For
       End If
       Next j
    
    Next i
    
    End Sub
    The purpose of this code is to loop through each row in a table (C8:W37), find the first non-zero value, and copy paste the value in row 6 of that column into the same row but in column 2. The above code works just fine for what I want it to do.

    The problem is that the number of the rows in the table may change. So instead of Array(8 To 37, 3 To 23) I would want it to be like Array(8 To x, 3 To 23), where x would equal = ActiveSheet.Range("C8").End(xlDown).Row

    However, I cannot seem to accomplish this. Also for another purpose I would like to adapt this code to reverse the loop so that it work backwards like lets say Array(8 To 37, 23 To 3), but I cannot seem to accomplish this either. I am stuck and I don't know how to proceed to resolve these issues.

    Any assistance would be highly appreciated.
    Last edited by chrixton; 03-02-2014 at 12:48 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 6
    Last Post: 09-25-2013, 10:08 PM
  2. Populate a Single Dimensional Array with two Dim Array (matrix)
    By Benjamin1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2011, 12:49 PM
  3. Dynamic 2 dimensional array in VBA class
    By dlx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2010, 09:20 PM
  4. Creating a 2-dimensional array from a 1-dimensional list
    By guywithcamera in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-27-2008, 06:34 PM
  5. [SOLVED] Create One-Dimensional Array from Two-Dimensional Array
    By Stratuser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2005, 05:06 PM

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