ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sum new Column Added (https://www.excelbanter.com/excel-programming/394970-sum-new-column-added.html)

Jul in Ohio[_2_]

Sum new Column Added
 
I have Excell XP 2002, I have a macro that inserts two columns one is a date
field and one is a number field.

After inserting the number column I would like to have a macro to place a
sum formula in row 27 of the column. Any ideals.

I have tried a couple others that have been offered, and nothing seems to be
working.


Susan

Sum new Column Added
 
try using the macro recorder. turn it on, then
insert column
write your sum formula in row 27
turn off macro recorder.

the resulting macro code should give you a pretty good place to start
- you could probably just copy & paste that code into your current
macro.
:)
susan


On Aug 7, 10:30 am, Jul in Ohio
wrote:
I have Excell XP 2002, I have a macro that inserts two columns one is a date
field and one is a number field.

After inserting the number column I would like to have a macro to place a
sum formula in row 27 of the column. Any ideals.

I have tried a couple others that have been offered, and nothing seems to be
working.




Don Guillett

Sum new Column Added
 
try
Sub insertcolumnsandsum()
ac = ActiveCell.Column
ar = 1
With Cells(ar, ac)
.Resize(, 2).EntireColumn.Insert
.Offset(27, 0).Formula = _
"=sum(r1c" & ac + 2 & ":r27c" & ac + 2 & " )"
End With
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Jul in Ohio" wrote in message
...
I have Excell XP 2002, I have a macro that inserts two columns one is a
date
field and one is a number field.

After inserting the number column I would like to have a macro to place a
sum formula in row 27 of the column. Any ideals.

I have tried a couple others that have been offered, and nothing seems to
be
working.



Tom Ogilvy

Sum new Column Added
 
assume the first column is Date and the second is the values to be summed.

icol = 10
Columns(icol).Resize(,2).Insert
cells(27,icol + 1).Formula = "=Sum(K1:K26)"


Change the 10 to the column number of the new column which will be the date
column.

--
Regards,
Tom Ogilvy


"Jul in Ohio" wrote:

I have Excell XP 2002, I have a macro that inserts two columns one is a date
field and one is a number field.

After inserting the number column I would like to have a macro to place a
sum formula in row 27 of the column. Any ideals.

I have tried a couple others that have been offered, and nothing seems to be
working.


Tom Ogilvy

Sum new Column Added
 
Forgot to change the address in the formula when I decided to generalize the
macro.

cells(27,icol + 1).Formula = "=Sum(K1:K26)"
should be

cells(27,icol + 1).FormulaR1C1 = "=Sum(R1C:R26C)"

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

assume the first column is Date and the second is the values to be summed.

icol = 10
Columns(icol).Resize(,2).Insert
cells(27,icol + 1).Formula = "=Sum(K1:K26)"


Change the 10 to the column number of the new column which will be the date
column.

--
Regards,
Tom Ogilvy


"Jul in Ohio" wrote:

I have Excell XP 2002, I have a macro that inserts two columns one is a date
field and one is a number field.

After inserting the number column I would like to have a macro to place a
sum formula in row 27 of the column. Any ideals.

I have tried a couple others that have been offered, and nothing seems to be
working.



All times are GMT +1. The time now is 11:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com