Consulting

Results 1 to 6 of 6

Thread: Application-defined or object-defined error

  1. #1

    Application-defined or object-defined error

    Okay, the error is occurring when the selection variable is run. Although, the MsgBox below actually displays with the correct vale which means that it actually gets past that point :S

    It displays the error after I click "OK" on the MsgBox:
    Run-time error '1004':
    
    Application-defined or object-defined error
    Here is the code, please note I am a noob at vba and have not yet learnt how to use it properly.
    [vba]
    Sub displayTask()
    Application.ScreenUpdating = False
    Dim cell, task, count, nTasks As Variant
    Dim selection, save_selection As Variant
    cell = Sheets("Marks Sheet").Range("task_display")

    ' Get the selected cell name and save for later use. Also find number of tasks in course
    selection = ActiveCell.Name.Name
    MsgBox (selection)
    save_selection = ActiveCell.Address
    nTasks = Sheets("Tasks").Range("number_of_tasks")

    ' Select the cell corresponding and jump to the right for the task data
    count = 0

    ' Select tasks sheet for searching
    Sheets("Tasks").Select
    Range("A1").Select

    'Search for task
    Do While count < nTasks
    If ActiveCell.Value = selection Then
    Dim task_data As Variant
    task_data = ActiveCell.Offset(0, 1).Value
    Sheets("Marks Sheet").Range("D24").Value = task_data

    End
    Else
    ActiveCell.Offset(1, 0).Select
    End If
    count = count + 1
    Loop
    Sheets("Marks Sheet").Range(save_selection).Select
    End Sub
    [/vba]

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Are you able to post the workbook?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Can you post a sample workbook?
    Peace of mind is found in some of the strangest places.

  4. #4
    Attached sample workbook.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    When I looked at your workbook if failed here when I tried to enter my name

    [vba]Sub cGrade()
    ' This function calculates the amount of points needed to get the next level

    Dim currentGrade, nGrade As Variant
    Select Case Sheets("Final Grade Sheet").Range("overall_grade").Value
    Case "Fail"
    currentGrade = Sheets("Final Grade Sheet").Range("E14")
    Case "PP"
    currentGrade = Sheets("Final Grade Sheet").Range("E15")
    Case "PM"
    currentGrade = Sheets("Final Grade Sheet").Range("E16")
    Case "MM"
    currentGrade = Sheets("Final Grade Sheet").Range("E17")
    Case "MD"
    currentGrade = Sheets("Final Grade Sheet").Range("E18")
    Case "DD"
    currentGrade = Sheets("Final Grade Sheet").Range("G18")
    End Select
    nGrade = currentGrade - Sheets("Final Grade Sheet").Range("K9")
    Sheets("Marks Sheet").Range("next_grade").Value = nGrade
    End Sub[/vba]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Your code is looping. You need to disable events to prevent sheet events from running where not required.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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