ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   how do I create independent results? (https://www.excelbanter.com/excel-worksheet-functions/260182-re-how-do-i-create-independent-results.html)

pbart

how do I create independent results?
 
Brute force and ignorance but it does it.
Extending to more cars/drivers gets very tedious.

A little more finesse anyone.




Sub assignDriver()

Dim driverName(4) As String
Dim i As Integer

'Assign driver names to array
driverName(1) = "Steve"
driverName(2) = "Mary"
driverName(3) = "Craig"
driverName(4) = "Alison"

'Write headings
Cells(1, 1) = "index"
Cells(1, 2) = "Car1"
Cells(1, 3) = "Car2"
Cells(1, 4) = "Car3"
Cells(1, 5) = "Car4"

i = 0
For driverCar1 = 1 To 4
For driverCar2 = 1 To 4
If driverCar2 < driverCar1 Then
For driverCar3 = 1 To 4
If driverCar3 < driverCar1 Then
If driverCar3 < driverCar2 Then
For driverCar4 = 1 To 4
If driverCar4 < driverCar1 Then
If driverCar4 < driverCar2 Then
If driverCar4 < driverCar3 Then
i = i + 1
Cells(i + 1, 1) = i
Cells(i + 1, 2) =
driverName(driverCar1)
Cells(i + 1, 3) =
driverName(driverCar2)
Cells(i + 1, 4) =
driverName(driverCar3)
Cells(i + 1, 5) =
driverName(driverCar4)
End If
End If
End If
Next driverCar4
End If
End If
Next driverCar3
End If
Next driverCar2
Next driverCar1
End Sub


"Mark" wrote:

I am NOT a seasoned user, so forgive me if this questions is too simple:
I have 4 cars and 4 drivers. I want Excel to fill-out the possibilities of
drivers.
1 = Steve
2 = Mary
3 = Craig
4 = Allison
If I remember from my Algebra days, there should be 24 independent results
(1x2x3x4= 24) Please Help



All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com