I'm currently working on an MSWORD Checklist which contains a table with three columns, 1st describes the check, 2nd has 18 checkboxes and acts as the initial check, 3rd has 8 checkboxes and act as the crosscheck.
I'm looking to shuffle the checkboxes in column 3 among the different listed values in column 1
For example: Table 2: The 3 checkboxes should be shuffled randomly across rows 3-9
I currently have a piece of code which somewhat works. It can shuffle text in a table but only using column 1, instead of column 3. It also doesn't recognize headers from the range its actually supposed to use, which are the rows with the values.
Sub Shuffleboxes()
Dim numberOfRows As Integer
Dim currentRowText As String
Dim I As Integer
Dim doc As Document
Set doc = ActiveDocument
'Find the number of rows in the first table of the document
numberOfRows = doc.Tables(1).Rows.Count
'Initialise (seed) the random number generator
Randomize
'For each row in the table
For I = 1 To numberOfRows
'Find a new row number (any row in the table)
newRow = Int(numberOfRows * Rnd + 1)
'Unless we're not moving to a new row
If newRow <> I Then
'Get the current row text
currentRowText = CleanUp(doc.Tables(1).Cell(I, 1).Range.Text)
'Overwrite the current row text with the new row text
doc.Tables(1).Cell(I, 1).Range.Text = CleanUp(doc.Tables(1).Cell(newRow, 1).Range.Text)
'Put the current row text into the new row
doc.Tables(1).Cell(newRow, 1).Range.Text = currentRowText
End If
Next I
End Sub
I've added a screen shot of my word document in order to illustrate everything better.
Thanks in advance for your help.
much appreciated.
Florian
Aucun commentaire:
Enregistrer un commentaire