+ Reply to Thread
Results 1 to 6 of 6

Matix

Hybrid View

  1. #1
    Registered User
    Join Date
    01-09-2015
    Location
    Turket
    MS-Off Ver
    2013
    Posts
    64

    Matix

    I need a matrix that I do not know 4x4 or 5x5. It changes case by case.
    So how can I creat a matrix?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,918

    Re: Matix

    Sub Test()
    
    Dim vMatrix()
    
    Const x As Long = 4
    Const y As Long = 4
    
    vMatrix = Range("A1:C3")
    
    'ReDim vMatrix(1 To x, 1 To y)
    ReDim Preserve vMatrix(1 To x, 1 To y)
    
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-09-2015
    Location
    Turket
    MS-Off Ver
    2013
    Posts
    64

    Re: Matix

    Quote Originally Posted by TMS View Post
    Sub Test()
    
    Dim vMatrix()
    
    Const x As Long = 4
    Const y As Long = 4
    
    vMatrix = Range("A1:C3")
    
    'ReDim vMatrix(1 To x, 1 To y)
    ReDim Preserve vMatrix(1 To x, 1 To y)
    
    End Sub

    Regards, TMS
    Why did you write Last 2 line? for what?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,918

    Re: Matix

    vMatrix = Range("A1:C3")
    reads in a fixed worksheet range

    ReDim vMatrix(1 To x, 1 To y)
    would resize the matrix BUT destroy the contents

    ReDim Preserve vMatrix(1 To x, 1 To y)
    would resize the matrix but retain (preserve) the contents


    I wrote them because they are examples of resizing an array. I do not know what you will be doing or how you will be doing it hence some variations on a theme.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    01-09-2015
    Location
    Turket
    MS-Off Ver
    2013
    Posts
    64

    Re: Matix

    One more question,
     Dim matrix()
    For i = 2 To 10000
    
    If Cells(i, "C").Value = main_part Then
    matrix= Cells(i, "A").Value
    
    End If
    Next i
    Why it is not working? I cannot appoint variable to matrix

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,918

    Re: Matix

    Where is main_part defined? What does it contain?

    Option Explicit
    
    Sub Test2()
    
    Dim matrix(), i As Long
    Const main_part As String = "Test"
    
    ReDim matrix(1 To 10000)
    
    'For i = 2 To 10000
    For i = 2 To 30 ' for testin
        
        If Cells(i, "C").Value = main_part Then
            matrix(i) = Cells(i, "A").Value
            Debug.Print Range("A" & i); Range("C" & i); matrix(i)
        End If
    Next i
    End Sub

    Regards, TMS

+ 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. Creating Matix Table for various criteria...PLEASE HELP!
    By overmind007 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-17-2013, 05:19 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