How do I delete blank lines from a schedule using VBA

G

Gilgamesh

I need to programmatically delete blank lines from schedules.
I put this together but there's a problem

For Each Task in ActiveProject.Tasks
If Task is Nothing then Task.Delete
Next Task

Because the task is blank and therefore nothing in VBA the Delete method
does not work
Does anyone know how to get this working.

Thanks
 
J

John

Gilgamesh said:
I need to programmatically delete blank lines from schedules.
I put this together but there's a problem

For Each Task in ActiveProject.Tasks
If Task is Nothing then Task.Delete
Next Task

Because the task is blank and therefore nothing in VBA the Delete method
does not work
Does anyone know how to get this working.

Thanks

Gilgamesh,
Well you're right, if the task object is nothing then there is nothing
to delete.

Somewhere in the back of my mind I think I may have solved this one
before but I couldn't find it in my collection of macros. However, I
think this should do it.

[first sort the file by name, that will put the blank rows at the end]
Sub deleteblank()
Dim i As Integer
i = 1
NumTsk = activeproject.Tasks.count
SelectTaskColumn Column:="name"
For Each t In ActiveSelection.Tasks
If t Is Nothing Then
SelectRow Row:=i, rowrelative:=False, Height:=NumTsk - i
EditDelete
End If
i = i + 1
Next t

End Sub

John
Project MVP
 
J

Jan De Messemaeker

Hi,

This is how:

Sub delro()
For ro = ActiveProject.Tasks.Count To 1 Step -1
If ActiveProject.Tasks(ro) Is Nothing Then
SelectRow Row:=ro, rowrelative:=False
RowDelete
End If
Next ro
End Sub

HTH

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
D

Dean C

Everyone who runs macros should run Jan's macro frequently, because macros
can turn "Nothing" tasks into actual tasks as they run.
 
J

John

Dean C said:
Everyone who runs macros should run Jan's macro frequently, because macros
can turn "Nothing" tasks into actual tasks as they run.

Dean,
Care to explain that one (i.e. "macros can turn nothing tasks into
actual tasks as they run")?

John
 
J

Jack Dahlgren MVP

I think if you are working in the foreground on a cell by cell basis this
could possibly happen. For example if you are filling in cells putting data
in a blank line will make it a task.

I don't see how it could happen in the background since you have to address
a task to perform any action on it.

-Jack
 
D

Dean C

If you perform any action in a field such as paste or fill down, whether in a
macro or not, where you don't check to see if there is a task actually there,
then the nothing tasks will become one day duration tasks. I guess that might
be another way to get rid of nothing tasks, pick an empty field add a
character or number and fill down. Use a table that shows time and Filter for
the created date equals the date and time you filled down. Use the created
date instead of name = blank in case you have an actual task with the name
missing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top