Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Schedule table

Hi, is there a way to make this table in VBA?

Mon Tue Wed Thu Fri
A 1 2 3 4 5
B 2 1 5 3 4
C 3 4 1 5 2
D 4 5 2 1 3
E 5 3 4 2 1

What i need is a table with 5 schedules that can never repeat for one person
(A, B, C, D or E) in the week.
There are only 5 schedules in every day that should be distributed for the 5
persons

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Schedule table

Iforgot to say that i've been using this macro to random the schedules but
the problem is that it repeats the schedules:



Sub Gen5()
Dim varr(1 To 5) As Long
Dim varr1(1 To 5) As Long
Dim varr2(1 To 5) As Long
Dim varr3(1 To 5) As Long
Dim varr4(1 To 5) As Long

'colunas
Dim list(1 To 5) As Long
Dim list1(1 To 5) As Long
Dim list2(1 To 5) As Long
Dim list3(1 To 5) As Long
Dim list4(1 To 5) As Long

Dim i As Long, j As Long
Dim num As Long
For i = 1 To 5
varr(i) = i
varr1(i) = i
varr2(i) = i
varr3(i) = i
varr4(i) = i
Next

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr(num) < 0 Then
list(j) = varr(num)
varr(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr1(num) < 0 Then
list1(j) = varr1(num)
varr1(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr2(num) < 0 Then
list2(j) = varr2(num)
varr2(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr3(num) < 0 Then
list3(j) = varr3(num)
varr3(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr4(num) < 0 Then
list4(j) = varr4(num)
varr4(num) = 0
j = j + 1
End If
Loop



For i = 1 To 5
Cells(i, 1) = list(i)
Cells(i, 2) = list1(i)
Cells(i, 3) = list2(i)
Cells(i, 4) = list3(i)
Cells(i, 5) = list4(i)

Next

End Sub





"Pedro Costa" escreveu:

Hi, is there a way to make this table in VBA?

Mon Tue Wed Thu Fri
A 1 2 3 4 5
B 2 1 5 3 4
C 3 4 1 5 2
D 4 5 2 1 3
E 5 3 4 2 1

What i need is a table with 5 schedules that can never repeat for one person
(A, B, C, D or E) in the week.
There are only 5 schedules in every day that should be distributed for the 5
persons

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Schedule table

Sub aa()
Dim v(1 To 5) As Variant
Dim v1 As Variant
v(1) = Array(1, 2, 3, 4, 5)
v(2) = Array(5, 1, 2, 3, 4)
v(3) = Array(4, 5, 1, 2, 3)
v(4) = Array(3, 4, 5, 1, 2)
v(5) = Array(2, 3, 4, 5, 1)

For i = 1 To 10
j = Int(Rnd() * 5 + 1)
k = Int(Rnd() * 5 + 1)
If j < k Then
v1 = v(j)
v(j) = v(k)
v(k) = v1
End If
Next
For i = 1 To 5
Cells(i, 1).Resize(1, 5) = v(i)
Next
End Sub

--
Regards,
Tom Ogilvy



"Pedro Costa" wrote in message
...
Iforgot to say that i've been using this macro to random the schedules but
the problem is that it repeats the schedules:



Sub Gen5()
Dim varr(1 To 5) As Long
Dim varr1(1 To 5) As Long
Dim varr2(1 To 5) As Long
Dim varr3(1 To 5) As Long
Dim varr4(1 To 5) As Long

'colunas
Dim list(1 To 5) As Long
Dim list1(1 To 5) As Long
Dim list2(1 To 5) As Long
Dim list3(1 To 5) As Long
Dim list4(1 To 5) As Long

Dim i As Long, j As Long
Dim num As Long
For i = 1 To 5
varr(i) = i
varr1(i) = i
varr2(i) = i
varr3(i) = i
varr4(i) = i
Next

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr(num) < 0 Then
list(j) = varr(num)
varr(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr1(num) < 0 Then
list1(j) = varr1(num)
varr1(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr2(num) < 0 Then
list2(j) = varr2(num)
varr2(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr3(num) < 0 Then
list3(j) = varr3(num)
varr3(num) = 0
j = j + 1
End If
Loop

j = 1
Do While j < 6
num = Int(Rnd * 5 + 1)
If varr4(num) < 0 Then
list4(j) = varr4(num)
varr4(num) = 0
j = j + 1
End If
Loop



For i = 1 To 5
Cells(i, 1) = list(i)
Cells(i, 2) = list1(i)
Cells(i, 3) = list2(i)
Cells(i, 4) = list3(i)
Cells(i, 5) = list4(i)

Next

End Sub





"Pedro Costa" escreveu:

Hi, is there a way to make this table in VBA?

Mon Tue Wed Thu Fri
A 1 2 3 4 5
B 2 1 5 3 4
C 3 4 1 5 2
D 4 5 2 1 3
E 5 3 4 2 1

What i need is a table with 5 schedules that can never repeat for one

person
(A, B, C, D or E) in the week.
There are only 5 schedules in every day that should be distributed for

the 5
persons

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Schedule table

Thank you very much for your post, it works just the way i need ...

And if i want to assign a certain schedule to a certain week day, is it
possible to have a macro to fill the cells that are empty?

Thanks


"Pedro Costa" escreveu:

Hi, is there a way to make this table in VBA?

Mon Tue Wed Thu Fri
A 1 2 3 4 5
B 2 1 5 3 4
C 3 4 1 5 2
D 4 5 2 1 3
E 5 3 4 2 1

What i need is a table with 5 schedules that can never repeat for one person
(A, B, C, D or E) in the week.
There are only 5 schedules in every day that should be distributed for the 5
persons

Thanks

Reply
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
Tennis Schedule - Schedule players randomly Chris M. Excel Discussion (Misc queries) 5 September 24th 09 09:48 PM
Lab Schedule - with Pivot table John Wicks Excel Discussion (Misc queries) 0 May 22nd 07 04:16 AM
How to schedule a pivot table in excel 2003? CY Excel Discussion (Misc queries) 3 March 27th 06 10:59 PM
Create patient schedule based on master therapist schedule PapaBear Excel Discussion (Misc queries) 8 October 12th 05 04:56 AM
Pay off schedule exsam21 Excel Discussion (Misc queries) 0 June 1st 05 08:08 PM


All times are GMT +1. The time now is 02:25 AM.

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

About Us

"It's about Microsoft Excel"