+ Reply to Thread
Results 1 to 3 of 3

How to formulate a one-dimensional array from the elements of a two-dimensional one?

  1. #1
    Registered User
    Join Date
    01-24-2023
    Location
    London, England
    MS-Off Ver
    2021 Professional Plus
    Posts
    3

    How to formulate a one-dimensional array from the elements of a two-dimensional one?

    I made this matrix code:

    Sub matrix1()
    Const N = 7, M = 7
    Dim Z(1 To N, 1 To M), I, J As Integer

    For I = 1 To N
    For J = 1 To M
    Z(I, J) = Int(-6 + Rnd * (10 + 6))
    Next J
    Next I

    Worksheets("Sheet1").Cells(1, 1).Resize(N, M).Value = Z
    End Sub


    And I need the code of a one-dimensional array of the positive elements of this matrix.

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: How to formulate a one-dimensional array from the elements of a two-dimensional one?

    Hello. Try with:

    PHP Code: 
    Sub Matrix2()
    Const 
    77
    Dim Z
    (1 To N1 To M), As IntegerAs IntegerWAs Long
    Rem 
    -----------------\
    For 
    1 To N
      
    For 1 To M
        Z
    (IJ) = Int(-Rnd * (10 6))
      
    Next
    Next
    Worksheets
    ("Sheet1").Cells(11).Resize(NM).Value Z
    Rem 
    -----------------\
    ReDim W(1 To N M)
    For 
    1 To N
      
    For 1 To M
        
    If Z(IJ) > 0 Then
          R 
    R
          W
    (R) = Z(IJ)
        
    End If
      
    Next
    Next
    Rem 
    -----------------\
    If 
    0 Then Worksheets("Sheet1").Range("A10").Resize(, R) = W
    Worksheets
    ("Sheet1").UsedRange.Columns.AutoFit
    End Sub 
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  3. #3
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: How to formulate a one-dimensional array from the elements of a two-dimensional one?

    Thanks for the +rep.

+ 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. How do you shift elements in a 2 dimensional array by a variable amount?
    By max3732 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2020, 12:38 PM
  2. [SOLVED] have 1 dimensional array, trying to create a 2 dimensional array, runtime 9
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2019, 07:03 AM
  3. [SOLVED] Convert two-dimensional array elements to cumulative sums
    By jakebryant in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 07-06-2018, 08:09 PM
  4. [SOLVED] Convert 2 dimensional array to 1 dimensional
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2018, 05:20 AM
  5. Parse Data from one dimensional array into a 2 dimensional array.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:29 AM
  6. Filling all elements of a two dimensional array?
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-03-2009, 11:38 AM
  7. 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

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