none
How to fill a table randomly or simetric RRS feed

  • Question

  • Hi,

    I have a 5x5 table.  What I am trying to do is to fill the cells (i,j) and (j,i) at the same time by using two different groups. (For that I used 2 frames, so I can choose 2 radiobuttons at the same time.) 

    I tried to write the code like that, but I believe there are some things missing.

    Dim i As Integer
    Dim j As Integer
       
    If OptionButton1.Value = True Then
        ActiveCell.Row = i
        ActiveCell.Column = j
        
       ThisWorkbook.Sheets("Sheet1").Cells(j, i).Value = 3
       

    And I  want to put a random button so I can give 10 values randomly, but I couldn't figure out how exactly we use the random function. Because I just want the button to choose a random cell over and over again, not the value.




    • Edited by excelibur Thursday, November 27, 2014 8:18 PM
    Thursday, November 27, 2014 8:15 PM

Answers

  • Hi Excelibur,

    >>And I  want to put a random button so I can give 10 values randomly, but I couldn't figure out how exactly we use the random function. <<

    Here is a sample generate a random integer value from lowerboundto upperbound for your reference:

    Dim result(10) As Integer
    upperbound = 20
    lowerbound = 10
    For i = 0 To 10
    result(i) = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    Next i

    And you can get more detail about the rnd function from link below:
    Rnd Function

    >>. Because I just want the button to choose a random cell over and over again, not the value.<<

    You can move the active cell to a random cell with the rand numbers. For example, we can choose the top left cell to be beginner cell and generate the random width and height offest. Then we can use Range.Offset Property to select a cell and acitve it.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 1, 2014 2:50 AM
    Moderator