martynball
05-06-2010, 10:03 PM
For some reason an error occurs after the "selection" variable is executed... Although, a MsgBox executes fine if I place it just after the "selection" variable and make it display that variable, it also has the correct value in it...
When I click "OK" the error comes up...
Error:
Run-time error '1004':
Application-defined or object-defined error
VBA:
Sub displayTask()
' Application.ScreenUpdating = False
Dim cell, task, count, nTasks, selection, save_selection As Variant
' Get the selected cell name and save for later use. Also find number of tasks in course
selection = ActiveCell.Name.Name
save_selection = ActiveCell.Address
nTasks = Sheets("Tasks").Range("number_of_tasks")
'Set some variables
count = 0
' Select tasks sheet for searching
Sheets("Tasks").Select
Range("A1").Select
'Search for task
Do While count < nTasks
MsgBox ("ds")
If ActiveCell.Value = selection Then
Dim task_data As Variant
' Jump the right to get task data
task_data = ActiveCell.Offset(0, 1).Value
'Sheets("Marks Sheet").Range("D24").Value = task_data
MsgBox (task_data)
End
Else
ActiveCell.Offset(1, 0).Select
End If
count = count + 1
Loop
' Sheets("Marks Sheet").Range(save_selection).Select
End Sub
When I click "OK" the error comes up...
Error:
Run-time error '1004':
Application-defined or object-defined error
VBA:
Sub displayTask()
' Application.ScreenUpdating = False
Dim cell, task, count, nTasks, selection, save_selection As Variant
' Get the selected cell name and save for later use. Also find number of tasks in course
selection = ActiveCell.Name.Name
save_selection = ActiveCell.Address
nTasks = Sheets("Tasks").Range("number_of_tasks")
'Set some variables
count = 0
' Select tasks sheet for searching
Sheets("Tasks").Select
Range("A1").Select
'Search for task
Do While count < nTasks
MsgBox ("ds")
If ActiveCell.Value = selection Then
Dim task_data As Variant
' Jump the right to get task data
task_data = ActiveCell.Offset(0, 1).Value
'Sheets("Marks Sheet").Range("D24").Value = task_data
MsgBox (task_data)
End
Else
ActiveCell.Offset(1, 0).Select
End If
count = count + 1
Loop
' Sheets("Marks Sheet").Range(save_selection).Select
End Sub