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
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