LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.newusers,microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Random Function in VB

I am trying to use the Random Function in VB to generate a series of Random
numbers equal to a counter that is date based. and insert the random numbers
into a cell on the same spreadsheet. I am having some problems getting it to
work, any help would be appreciated as I am not a VB programmer. The Code is
below:

Dim StartDate As Date ' Advisor Start Date
Dim GroupCount As Integer ' Counter for determining how many
advisors with same start date
Dim RandomNumber As Integer ' Random number value generated by Randomize
function

'
' Macro recorded 2004-05-14 by Jim Campbell
' This Macro was created to generate random numbers to be used
' in determining the order of choice based upon the same date
' within a group
'
'
' Specify Worksheet and column to work with

Sub Column_Select()
Worksheets("Lottery").Columns (4) ' Start date of Advisor
End Sub

' Check_Start_Date Format (DD-MON-YYYY) will determine number
' to be used for next module that generates Random Numbers.
' GroupCount determines how many random numbers are generated
' based upon Start Date
'
'
Sub Check_Start_Date()
Check = True: GroupCount = 0 ' Initialize variables.
Do ' Outer loop.
Do While StartDate = StartDate ' Inner loop.
GroupCount = GroupCount + 1 ' Increment Counter.
If StartDate < StartDate Then 'If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately
End Sub

' Use GroupCount value as input for
' module that generates Random Numbers
'
'
Sub Random_Number()

Randomize ' Initialize random-number generator.
RandomNumber = Int((GroupCount * Rnd) + 1) ' Generate random number
based on GroupCount
End Sub

'
' If cell is is not empty, add value to worksheet
' Add column with Random Number value to Lottery.xls
'
'
Sub Add_Column()
For Each c In Worksheets("Lottery").Range(RandomNumber).Cells ' Specify
cells that will be populated with number
If c.Value < Null Then
With Worksheets("Lottery").Column(5).Add = RandomNumber ' Add random
number to Lottery.xls(column 5)
End With
End If
Next c
End Sub





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
random between function Arthur Excel Worksheet Functions 8 April 27th 09 08:15 AM
VBA "Rnd" Function: Truly Random? TheRobsterUK Excel Discussion (Misc queries) 2 September 27th 05 04:50 AM
How can I use the random function? petevang Excel Worksheet Functions 1 July 11th 05 03:50 PM
Random Function Troy[_3_] Excel Programming 3 April 4th 04 07:49 AM
Random function Chris Excel Programming 3 November 5th 03 03:59 AM


All times are GMT +1. The time now is 05:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"