Anyone have code to return to row and column where macro started?

L

luis

If I start the macro from a current task/cell, then run some code that
loops through the view, how do I get back to where I started?

Thanks for any tips!!

Luis
 
M

Mike Glen

Hi Luis,

Try posting on the developer newsgroup. Please see FAQ Item: 24. Project
Newsgroups. FAQs, companion products and other useful Project information
can be seen at this web address: http://www.mvps.org/project/.

Mike Glen
Project MVP
 
L

Luis Contreras

Solution: (Using MSP 2000) This code gets you back to where you started when you ran the macro.

Sub BackToStartingRow()
tRow = ActiveCell.Task.ID 'Gets current row
'insert whatever code you want to run
SelectEnd 'Moves to bottom
SelectBeginning 'Moves to top
SelectRow (tRow - 1) 'For some reason, -1 puts you back at starting row
End Sub

Hope this helps someone.

Luis
 
J

John

Luis,
The reason the "-1" in the SelectRow statement puts the selection back
to the original cell is because the default for the RowRelative option
of the SelectRow method is "true". Therefore the ID value of tRow is no
longer absolute but relative to the first task (i.e the beginning). Set
the RowRelative option to "false" and the "-1" isn't needed. Be aware
also that the ID number is absolute but the SelectRow method applies to
the current active view. For example, set a filter that removes a task
somewhere between the beginning and the original selected task in the
current view and run the code (e.g. select task ID 10 and set a filter
to remove task 5 from the current view). Run the code and note which row
is selected now.

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