Hi,
I'm using the following code to calculate all combinations of 3 variables.
found in this thread
This code calculates all combinations starting from row 1. I would like to have a header in row 1. Can the code be adjusted in that way or would that be too hard ?
regards
Stefan
I'm using the following code to calculate all combinations of 3 variables.
found in this thread
Code:
Sub Perm()Dim rSets As Range, rOut As Range
Dim vArr As Variant, lrow As Long
Set rSets = Range("A1").CurrentRegion
ReDim vArr(1 To rSets.Columns.Count)
Set rOut = Cells(1, rSets.Columns.Count + 2)
Perm1 rSets, vArr, rOut, 1, lrow
End Sub
Sub Perm1(rSets As Range, ByVal vArr As Variant, rOut As Range, ByVal lSetN As Long, lrow As Long)
Dim j As Long
For j = 1 To rSets.Rows.Count
If rSets(j, lSetN) = "" Then Exit Sub
vArr(lSetN) = rSets(j, lSetN)
If lSetN = rSets.Columns.Count Then
lrow = lrow + 1
rOut(lrow).Resize(1, rSets.Columns.Count).Value = vArr
Else
Perm1 rSets, vArr, rOut, lSetN + 1, lrow
End If
Next j
End Sub
This code calculates all combinations starting from row 1. I would like to have a header in row 1. Can the code be adjusted in that way or would that be too hard ?
regards
Stefan