Hello everyone, my name is enrique and i have come to a problem while trying to modify a VBA to give me specific information. When i run the VBA it gives me the error - "run-time error "1004": Application-defined or object-defined error". How can i fix this issue. I am trying to develop a VBA that will give me all permutations possible, up to 3 variables. The original VBA that i have that works gives your permutations up to six variables. Ive gotten this far on the VBA, if anyone could help fix it or point me in the right direction would be great. Ive been reading on how to fix it but I still get the same error.
This is the VBA on working on
Sub GolfOpt()
Application.ScreenUpdating = False
Dim n, k, z As Integer
Dim m, BinCoeff, MaxCap, Ctr, Cost, RowCtr As Long
Dim MyRoster() As Variant
Dim G1, G2, G3 As Variant
k = 3
MaxCap = 50000
n = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
BinCoeff = Application.WorksheetFunction.Combin(n, k)
ReDim MyRoster(1 To BinCoeff, 1 To k + 1)
Ctr = 1
For G1 = 1 To n - 2
For G2 = G1 + 1 To n - 1
For G3 = G2 + 1 To n - n
Cost = 0
MyRoster(Ctr, 1) = G1
Cost = Cost + Sheets(1).Cells(G1, 2)
MyRoster(Ctr, 2) = G2
Cost = Cost + Sheets(1).Cells(G2, 2)
MyRoster(Ctr, 3) = G3
Cost = Cost + Sheets(1).Cells(G3, 2)
MyRoster(Ctr, 4) = Cost
Cost = Cost + Sheets(1).Cells(G4, 2)
Ctr = Ctr + 1
Next G3
Next G2
Next G1
Sheets(2).Cells.Clear
Sheets(2).Cells(1, 1) = "Cost"
Sheets(2).Cells(1, 1).Font.Bold = True
For z = 1 To 3
Sheets(2).Cells(1, z + 1) = "Player " & z
Sheets(2).Cells(1, z + 1).Font.Bold = True
Next z
RowCtr = 2
For m = 1 To BinCoeff
If MyRoster(m, 4) <= MaxCap Then
Sheets(2).Cells(RowCtr, 1) = MyRoster(m, 4)
For z = 1 To 3
Sheets(2).Cells(RowCtr, z + 1) = Sheets(1).Cells(MyRoster(m, z), 1)
Next z
RowCtr = RowCtr + 1
End If
Next m
Sheets(2).Activate
Sheets(2).Columns("A:A").Select
Sheets(2).Sort.SortFields.Clear
Sheets(2).Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortTextAsNumbers
With Sheets(2).Sort
.SetRange Sheets(2).UsedRange
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.ScreenUpdating = True
End Sub
The highlighted part is where it says the error is happening
Bookmarks