PDA

View Full Version : Find and Link Tasks in VBA



didless
02-05-2016, 07:48 AM
OK, hopefully someone can help me.
I am trying to write a macro that can find a task that satisfies certain criteria and then link it to a successor that also satisfies certain criteria.

Essentially what I have is a project for a building site with many plots for houses all with the same tasks being completed on each house (all the tasks have the same name for each plot). What I want to do is Link the first bricklaying tasks on one plot to the the first bricklaying task on another plot. I want to automate this process to save time.

What I have set up is an input box in which the user identifies the 2 plots to link, and then I have managed to use the find function to identify the tasks on each plot that are needed, but actually trying to set the Task to be able to link it is proving a problem.
In Text6 field I have the plot number and task brought together in one cell.


Below is what I have in VBA so far. What I have at the moment brings back a Type mismatch error on the 'Set Brick1A = ActiveCell line. I cant seem to find a way to reference the active cell as a task for it to link. Any ideas??

Thanks,
Dave

Sub LinkAuto()
Dim plot As String
Dim Brick1A As Task
Dim Brick1B As Task


plotA = InputBox("Type first plot number in box below - NB, precede numbers less than 10 with 0", "Plot no A")
plotB = InputBox("Type second plot number in box below - NB, precede numbers less than 10 with 0", "Plot no B")
Find Field:="Text6", test:="equals", Value:="Plot " & plotA & "Brickwork 1"
Application.SelectTaskCell
Set Brick1A = ActiveCell


Find Field:="Text6", test:="equals", Value:="Plot " & plotB & "Brickwork 1"
Application.SelectTaskCell
Set Brick1B = ActiveCell


Brick1A.LinkSuccessors Tasks:=Brick1B




End Sub

grabowskijr
08-04-2016, 08:31 PM
I know that it has been a while since you posted this. Hopefully you found the solution already. Looks like you were really close. Just needed to add .task to 2 lines. You have a type mismatch because you have Brick1A dimensioned as a Task. So you need to set it to the Activecell.task object.

Sub LinkAuto()
Dim plot As String
Dim Brick1A As Task
Dim Brick1B As Task


plotA = InputBox("Type first plot number in box below - NB, precede numbers less than 10 with 0", "Plot no A")
plotB = InputBox("Type second plot number in box below - NB, precede numbers less than 10 with 0", "Plot no B")
Find Field:="Text6", test:="equals", Value:="Plot " & plotA & "Brickwork 1"
Application.SelectTaskCell
Set Brick1A = ActiveCell.task

Find Field:="Text6", test:="equals", Value:="Plot " & plotB & "Brickwork 1"
Application.SelectTaskCell
Set Brick1B = ActiveCell.task


Brick1A.LinkSuccessors Tasks:=Brick1B

End Sub