PDA

View Full Version : Application-defined or object-defined error



martynball
05-06-2010, 10:52 AM
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.

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

Aussiebear
05-06-2010, 11:18 AM
Are you able to post the workbook?

austenr
05-06-2010, 11:19 AM
Can you post a sample workbook?

martynball
05-06-2010, 12:57 PM
Attached sample workbook.

Aussiebear
05-09-2010, 12:19 PM
When I looked at your workbook if failed here when I tried to enter my name

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

mdmackillop
05-09-2010, 12:44 PM
Your code is looping. You need to disable events to prevent sheet events from running where not required.