Active ROW number ?

L

laurentg

Hi everybody

I'm quite new with VBA and would appreciate your help to
determine what I would call the active row number, the
row number (not task number) of the active cell

Thanks very much in advance
Regards
Laurent
 
J

Jan De Messemaeker

Hi,

I can't imagine what you would do with it, but should I ever need it, I
would:
memorise activecell.task.id
then selectall
And loop through the activeselection.tasks (counting the steps) till you
meet the task.id just saved.
HTH

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
Project Management Consultancy
Prom+ade BVBA
32-495-300 620
 
J

John

Laurent,
Being new to VBA in Project and talking about row numbers, it sounds
like you have worked with Excel a fair amount. In Project "row" numbers
are analogous to tasks. And except for dynamically consolidated master
files, the task number (represented by the ID) is the row number.

Depending on how the VBA code is written (i.e. background processing or
foreground processing), the "active" task/row can be referred to several
different ways. For example, lets say you want to get the name of task
number 5. Using "TskNam" as a variable to hold the name, the syntax is:
TskNam = ActiveProject.Tasks(5).Name

A more common approach is to use background processing. The following
code loops through all tasks in the project
For each t in ActiveProject.Tasks
If Not t is Nothing Then
TskNam = t.Name
(do other operations as needed)
End If
Next t

As you see, there are many ways to get something done using VBA. If you
record a macro you will generally get foreground processing which tends
to run slower and be a little "clunkier". As you learn more of the code
syntax and how to use Project objects, programming in full object code
becomes easier, code runs faster and is cleaner (at least in my opinion).

Hope this has helped.
John
 
J

John

Laurent,
Before someone else points out my oversight, there is another case where
the "row" is not the task. Some people like to put blank lines in their
project file to separate sections. Blank lines are not tasks but they of
course do create an ID. I never use this construct, hence I overlooked
it. Having blank lines however is the reason for the "If Not t is
Nothing Then" line in the code section I showed in my other post. It
effectively skips over blank lines if they exist.

John
 
L

laurentg

Thanks very much for your reply gentlemen. I already came
to this myself but this doesn't help me to address my
real problem

Thanks again
Laurent
 
J

Jan De Messemaeker

That is very, very curious since I did give a solution.
Maybe you don't like it, but if it isn't the solution to your problem, then
you did noyt explain your problem properly, I am afraid.
My post definitely gave the solution of how to find the row of the active
cell.
(John do not forget views can be filtered or sorted; row and ID may be miles
apart)

HTH
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
Project Management Consultancy
Prom+ade BVBA
32-495-300 620
 
J

John

Jan,
Thanks, I was sure someone would cite another case where row doesn't
equal task - oh well.

Before I even read your response I guessed what you were going to say
about Laurent's reply. If our replies didn't solve his problem, I guess
the "problem" wasn't presented.

John
 
J

John

Laurent,
OK, now we know what you don't need (I guess). What exactly are you
trying to do? Perhaps if you back up a bit from the details an give a
larger picture, we can help find a solution.

John
 

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