Inserting a column

J

JJ

I want to be able to create a formula on a selected Number field and
insert that field to the left of the selected column. In order to do
this I know I would be using the TableEdit method. However, I would
need to know the existing Column number of the selected cell or column
in order to give a value to the "ColumnPosition" argument of the
TableEdit method.

What method or property would give me the column number (position in
the table) of the selected cell or column?

(NOTE: I already know how to set the custom formula. If no cell or
column is selected, then the default value for ColumnPosition would be
-1 to place the field at the end of the table.)

Thanks!
JR
 
R

Rod Gill

There isn't a property that provides the column position for the ActiveCell
object. However, you could loop thru the TaskField objects counting columns
until you get to the one you want:

Sub Test()
Dim FieldID As Long
Dim ActiveField As Long
Dim ColumnNo As Long
Dim fld As TableField
ActiveField = ActiveCell.FieldID
For Each fld In
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields
If fld.Field = ActiveField Then
ColumnNo = fld.Index
Exit For
End If
Next fld
End Sub

--

Rod Gill
Microsoft MVP for Project - http://www.project-systems.co.nz

Author of the only book on Project VBA, see: http://www.projectvbabook.com




JJ said:
I want to be able to create a formula on a selected Number field and
insert that field to the left of the selected column. In order to do
this I know I would be using the TableEdit method. However, I would
need to know the existing Column number of the selected cell or column
in order to give a value to the "ColumnPosition" argument of the
TableEdit method.

What method or property would give me the column number (position in
the table) of the selected cell or column?

(NOTE: I already know how to set the custom formula. If no cell or
column is selected, then the default value for ColumnPosition would be
-1 to place the field at the end of the table.)

Thanks!
JR

__________ Information from ESET Smart Security, version of virus
signature database 5073 (20100429) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 5073 (20100429) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
J

JJ

Thanks Rod! I know I can always count on you!

There isn't a property that provides the column position for the ActiveCell
object. However, you could loop thru the TaskField objects counting columns
until you get to the one you want:

Sub Test()
Dim FieldID As Long
Dim ActiveField As Long
Dim ColumnNo As Long
Dim fld As TableField
    ActiveField = ActiveCell.FieldID
    For Each fld In
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields
        If fld.Field = ActiveField Then
            ColumnNo = fld.Index
            Exit For
        End If
    Next fld
End Sub

--

Rod Gill
Microsoft MVP for Project -http://www.project-systems.co.nz

Author of the only book on Project VBA, see:http://www.projectvbabook.com










__________ Information from ESET Smart Security, version of virus signature database 5073 (20100429) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
J

JJ

FYI...

In case I needed this functionality for other purposes, I created a
function to provide me with this column number. I had to adjust some
of the code you wrote above for it to work. Here's the code:

Public Function SelectedColumnPosition()
Dim currPos As Integer
Dim currFldID As Long
Dim activeFld As TableField
Dim tblFlds As TableFields

currPos = -1
ActiveWindow.TopPane.Activate

Set tblFlds =
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields

currFldID = ActiveCell.FieldID

For Each activeFld In tblFlds
If activeFld.Field = currFldID Then
currPos = activeFld.Index
End If
Next

SelectedColumnPosition = currPos

End Function
 
R

Rod Gill

Put an Exit For row after currPos = activeFld.Index in case a user has
entered the same column twice (it does happen).

Good luck!

--

Rod Gill
Microsoft MVP for Project - http://www.project-systems.co.nz

Author of the only book on Project VBA, see: http://www.projectvbabook.com




JJ said:
FYI...

In case I needed this functionality for other purposes, I created a
function to provide me with this column number. I had to adjust some
of the code you wrote above for it to work. Here's the code:

Public Function SelectedColumnPosition()
Dim currPos As Integer
Dim currFldID As Long
Dim activeFld As TableField
Dim tblFlds As TableFields

currPos = -1
ActiveWindow.TopPane.Activate

Set tblFlds =
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields

currFldID = ActiveCell.FieldID

For Each activeFld In tblFlds
If activeFld.Field = currFldID Then
currPos = activeFld.Index
End If
Next

SelectedColumnPosition = currPos

End Function





__________ Information from ESET Smart Security, version of virus
signature database 5073 (20100429) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 5073 (20100429) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 

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