Results 1 to 5 of 5

How do i fix "Run-time error "1004" Application-defined or object-defined error"

Threaded View

  1. #1
    Registered User
    Join Date
    11-10-2015
    Location
    Orlando, FL
    MS-Off Ver
    Windows and MAC
    Posts
    3

    How do i fix "Run-time error "1004" Application-defined or object-defined error"

    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
    Last edited by 02Dade12; 11-13-2015 at 07:11 PM. Reason: Broke Forum Rules

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Frequently Used Macro now Giving a" Runtime Error '1004 Application-Object Defined Error"
    By rjw524 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-02-2015, 02:39 PM
  2. [SOLVED] Run time error:1004 "Application defined or Object defined error"
    By mvneema in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-07-2014, 09:47 AM
  3. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  4. Error When Implementing Code: "1004 - Application-defined or object-defined error"
    By blueblazingdemon in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-10-2013, 11:21 AM
  5. Replies: 1
    Last Post: 05-06-2013, 06:07 AM
  6. Run-time error "1004" Application defined or object-define-error
    By josros60 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-21-2013, 01:14 PM
  7. [SOLVED] 1004 "Application-defined or object-defined error"
    By guiu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-12-2006, 10:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1