Nick Vaughn
New Member
- Joined
- Jul 24, 2011
- Messages
- 12
Can anyone help me out on this one. I would like to have a formula for Subsets.
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys]Sub CombineAtoZx4_NoR()[/FONT]
[FONT=Fixedsys] Dim ws As Worksheet
Dim n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer
Dim iRow As Long, iColumn As Long, iCombinations As Long
Dim dStart As Date
Application.StatusBar = ""
Application.ScreenUpdating = False
dStart = Now()
Set ws = ThisWorkbook.Sheets(1)
ws.UsedRange.ClearContents
iCombinations = 0
iRow = 0
iColumn = 1[/FONT]
[FONT=Fixedsys] For n1 = Asc("A") To Asc("W")
For n2 = n1 + 1 To Asc("X")
For n3 = n2 + 1 To Asc("Y")
For n4 = n3 + 1 To Asc("Z")
iRow = iRow + 1
If iRow > 2000 Then
ws.Columns(iColumn).EntireColumn.AutoFit
iColumn = iColumn + 1
iRow = 1
Application.StatusBar = Format(iCombinations, "#,###") & " combinations found in " _
& Format(Now() - dStart, "hh:nn:ss")
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End If
ws.Cells(iRow, iColumn) = Chr(n1) & Chr(n2) & Chr(n3) & Chr(n4)
iCombinations = iCombinations + 1
Next n4
Next n3
Next n2
Next n1
ws.Columns(iColumn).EntireColumn.AutoFit
Application.ScreenUpdating = True
MsgBox Format(iCombinations, "#,###") & " combinations found" & Space(10) & vbCrLf & vbCrLf _
& "Run time: " & Format(Now() - dStart, "hh:nn:ss"), vbOKOnly + vbInformation[/FONT]
[FONT=Fixedsys]End Sub
[/FONT]
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Sub CombineNumericX4()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Const StartNumber As Long = 10
Const LastNumber As Long = 26[/FONT]
[FONT=Fixedsys]
Const MaxRows As Long = 10000
Dim ws As Worksheet
Dim n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer
Dim iRow As Long, iColumn As Long, iCombinations As Long
Dim dStart As Date
Application.StatusBar = ""
Application.ScreenUpdating = False
dStart = Now()
Set ws = ThisWorkbook.Sheets(3)
ws.UsedRange.ClearContents
iCombinations = 0
iRow = 0
iColumn = 1
For n1 = StartNumber To LastNumber - 3
For n2 = n1 + 1 To LastNumber - 2
For n3 = n2 + 1 To LastNumber - 1
For n4 = n3 + 1 To LastNumber
iRow = iRow + 1
If iRow > MaxRows Then
ws.Columns(iColumn).EntireColumn.AutoFit
iColumn = iColumn + 1
iRow = 1
Application.StatusBar = Format(iCombinations, "#,###") & " combinations found in " _
& Format(Now() - dStart, "hh:nn:ss")
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End If
ws.Cells(iRow, iColumn) = CStr(n1) & "," & CStr(n2) & "," & CStr(n3) & "," & CStr(n4)
iCombinations = iCombinations + 1
Next n4
Next n3
Next n2
Next n1
ws.Columns(iColumn).EntireColumn.AutoFit
Application.ScreenUpdating = True
MsgBox Format(iCombinations, "#,###") & " combinations found" & Space(10) & vbCrLf & vbCrLf _
& "Run time: " & Format(Now() - dStart, "hh:nn:ss"), vbOKOnly + vbInformation
[/FONT]
[FONT=Fixedsys]End Sub[/FONT][FONT=Fixedsys]
[/FONT]