+ Reply to Thread
Results 1 to 3 of 3

How create full spectrum 9 by 5 and 10 by 5 matrix?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2008
    Location
    Malaysia
    MS-Off Ver
    MS 2007
    Posts
    12

    How create full spectrum 9 by 5 and 10 by 5 matrix?

    Hi ALL,

    Can somebody teach me how to program a full spectrum 9 by 5 and 10 by 5 matrix that harbours numbers 1 to 45 and 1 to 50 respectively. I would also like to have a function that will allow me to randomize the matrices.

    Thanks in advance.

    Taylor

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Try these two macros. The second creates a randomised version.

    Sub Test()
    For N = 1 To 10
        For M = 1 To 5
            Counter = Counter + 1
            Cells(N, M) = Counter
        Next M
    Next N
    End Sub
    
    
    Sub Test2()
    For N = 1 To 10
        For M = 1 To 5
            MatrixSize = MatrixSize + 1
        Next M
    Next N
    Dim MatrixArray()
    ReDim MatrixArray(MatrixSize)
    For N = 1 To 10
        For M = 1 To 5
    TryAgain:
            X = Int((Rnd() * MatrixSize)) + 1
            UsedAlready = False
            For Y = 1 To MatrixSize
                If MatrixArray(Y) = X Then
                    UsedAlready = True
                    Exit For
                End If
            Next Y
            If UsedAlready = False Then
                Cells(N, M) = X
                For P = 1 To MatrixSize
                    If MatrixArray(P) = "" Then
                        MatrixArray(P) = X
                        Exit For
                    End If
                Next P
                MatrixArray(P) = X
            Else
                GoTo TryAgain
            End If
        Next M
    Next N
    
    
    
    End Sub
    Martin

  3. #3
    Registered User
    Join Date
    05-15-2008
    Location
    Malaysia
    MS-Off Ver
    MS 2007
    Posts
    12
    Thank you so much for the solution, Martin.

+ 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