adding columns

B

Bryan

I posted this in the charting forum but have received no replies. I am
doing this with a macro so maybe it should have been here in the programming
forum.

I need to add some columns to the right edge of the data page so I can do
some charting. From this forum I got the following line that will determine
the last column.
LastColumn = ActiveSheet.Cells.Find(what:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column

After running this macro LastColum might have the value of 7 (or 8 or 9,
etc). Knowing this, how do I go to the eighth column and start adding in
some data. Here is some pseudo code of what I need to do.

LastColumn = ActiveSheet.Cells.Find(what:="*", SearchOrder:=xlByColumns,
SearchDirection:=xlPrevious).Column
NewColumn = <LastColumn + 1>
ColumnA = <find_column_with_title_x>
ColumnB = >find_column_with_title_y>

NewColumn.row_2.FormulaR1C1 = ColumnA.row2 - ColumnB.row2
(In english: set the cell in row 2 of the new column equal to the value that
is in Column A row 2 minus Column B row 2. I cannot guarentee that the data
will be in any given column but I can guarentee the column header will be
known.)

Is this clear enough to solicit an answer?
Thank you,
Bryan
 
R

Rick Teale

Assuming that you are in the far right column . . .

NewColumn = LastColumn + 1
ActiveCell.Offset(0, NewColumn).Select

This code will move you "LastColumn + 1" from the active cell.
If you are not in the far right column, then you could use the following . .
..

MyColumn = ActiveCell.Column
NewColumn = LastColumn - MyColumn + 1
ActiveCell.Offset(0, NewColumn).Select
 
B

Bryan

I don't know how to use this. From what I can tell, I can now get the
selected column to be the first empty column to the right, but how do I
write something that says:

Row 1 of this column is "data xy" or any other lable
Row 2 of this column is equal to Column_A_Row_2 minus Column_B_Row_2.

Thanks for your time,
Bryan
 

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