how do i set up random numbers in a cell & row?

D

docook01

here is what I am trying to do: I have 6 rows like so

01 01 01 01 01 01

goin down rows 1-5 I want random numbers from 1-55, In row 6 I want random
numbers 1-42. How do i do that?
 
H

Helmut Weber

Hi,

Rows are horizontal, columns are vertical.
For a 6 x 6 table, or to be more precise,
for the first 6 rows and the first 6 columns
in a uniform table,
whereby uniform means, all rows got the same number of cells,
all columns got the same number of cells.

Sub Test444()
Dim oTbl As Table ' 1st table in doc
Dim r As Long ' row
Dim c As Long ' column
Randomize
Set oTbl = ActiveDocument.Tables(1)
With oTbl
For r = 1 To 6
For c = 1 To 5
oTbl.Cell(r, c).Range.Text = CLng(55 * Rnd + 1)
Next
c = 6
oTbl.Cell(r, c).Range.Text = CLng(42 * Rnd + 1)
Next
End With
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

For the purists:

[snip]
For r = 1 To 6
For c = 1 To 5
oTbl.Cell(r, c).Range.Text = CLng(55 * Rnd + 1)
Next
' c = 6 ' is redundant as c = 6 at that point of the code anyway
oTbl.Cell(r, c).Range.Text = CLng(42 * Rnd + 1)
Next
[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top