+ Reply to Thread
Results 1 to 3 of 3

Application-Defined or Object Defined Error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-20-2008
    Location
    Virginia
    MS-Off Ver
    2003
    Posts
    129

    Application-Defined or Object Defined Error

    All,

    I am getting an Application-defined or object defined error in the last line of my code below.

    
    
    Sub Compare()
    
        'Calls workOnSheet.  This opens up CostPoint file and formats for use.
        Call workOnSheet
        
        If StopFlag Then
           Exit Sub
        End If
        
        '===========================================================================================================
        'Get hours off of Timesheet Daily Detail Inquiry for the first Person.
       Set gplainId = ActiveSheet.Cells(3, 2) 'Find the employee Id of first person
       Set glastName = ActiveSheet.Cells(3, 3) 'Find the employee id of the first person
       Set gboldId = ActiveSheet.Cells(4, 2) 'Find the employee Id of the first person as bold
          
       With Workbooks(DEFName).Sheets("Page1_2").Range("A:A")
            Set ge = .Find(gplainId, LookIn:=xlValues)
            If IsEmpty(Worksheets("PATH").Cells(2, 2)) Then
                MsgBox "Requested Project Does Not Exist", vbExclamation, "No Such Project Code"
                Exit Sub
                Else:
                On Error Resume Next
                gbeginRow = Str(ge.Row)
                If Err.Number <> 0 Then
                    MsgBox "Requested Project Does Not Exist", vbExclamation, "No Such Project Code"
                    Exit Sub
                End If
                On Error GoTo 0
            End If
       End With
       
       Debug.Print gbeginRow
        
       With Workbooks(DEFName).Sheets("Page1_2").Range("B:B")
            Set gcell1 = Cells(gbeginRow, 2)
            Set gd = .Find(glastName, After:=gcell1, LookIn:=xlValues)
            gstartRow = Int(gd.Row)
       End With
        
       Debug.Print gstartRow
       With Workbooks(DEFName).Sheets("Page1_2").Range("A:A")
            Set gcell2 = Cells(gstartRow, 1)
            Set gc = .Find(gboldId, After:=gcell2, LookIn:=xlValues)
            gendRow = Int(gc.Row)
        End With
        Debug.Print gendRow
     
         '****** GOT TO HERE**********  Want to get the hours somehow and put in checker.
     ' You need to get a range for the employee id or name along with the charge code.  You don't have this at the moment.
        gsRng1 = Range(Cells(gstartRow, 2), Cells(gendRow, 2)).Address(False, False) ' Get the name with this one.
        gsRng2 = Range(Cells(gstartRow, 18), Cells(gendRow, 18)).Address(False, False) ' Get the hours with this one.
        gsRng3 = Range(Cells(gstartRow, 13), Cells(gendRow, 13)).Address(False, False) ' Get the charge codes with this one
        gsRef = "[" & DEFName & "]Page1_2"
        
         
         For gtheRow = 3 To 20
            ggetHours = "=SUMIF(" & gsRef & gsRng3 & ", """ & Cells(gtheRow, 5).Value & """, " & gsRef & gsRng2 & ")"
            Debug.Print ggetHours
            'Range("E5") = "GOT HERE"
            Cells(gtheRow, "F").Formula = ggetHours
    
    End Sub
    The code 'Cells(gtheRow, "F").Formula = ggetHours is throwing the error. Please help if you know what I am doing wrong. I have basically the same type of code in another workbook with a slight twist on it, and it does not throw an error out at me.

    Thank you -- SEOT

  2. #2
    Forum Contributor
    Join Date
    06-04-2013
    Location
    Moscow
    MS-Off Ver
    Office 365
    Posts
    100

    Re: Application-Defined or Object Defined Error

    If gsRef contains one of critical chars - error. You must add the single quote and necessarily - exclamation mark.
    gsRef="'[" & DEFName & "]Page1_2'!"
    I'm sorry my english...

  3. #3
    Forum Contributor
    Join Date
    05-20-2008
    Location
    Virginia
    MS-Off Ver
    2003
    Posts
    129

    Re: Application-Defined or Object Defined Error

    I did miss the explanation point! I should have known that much. I was not aware of the single quotes though. How did you know about those? What is the rule on those things? I am very greatly apprecaitive of you for fixing my code. It works now!! Thank you!!! -- SEOT

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Previously working code is now is now giving Application-defined or object-defined error
    By ready2learn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2014, 07:22 PM
  2. [SOLVED] application-defined/object-defined error 1004 when trying to read from or write to cells
    By florin_excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2012, 08:38 AM
  3. Replies: 2
    Last Post: 09-12-2012, 01:01 PM
  4. Application Defined or Object Defined Error, Command Button and Vlookup Function
    By stevedomer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-14-2011, 11:20 PM
  5. Replies: 3
    Last Post: 07-24-2006, 08:20 PM

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