Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
docook01 - 01 Sep 2006 15:08 GMT
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?
Helmut Weber - 01 Sep 2006 20:15 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber - 01 Sep 2006 21:49 GMT
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]

Signature

Helmut Weber, MVP WordVBA

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.