macro copying formula in active rows 
Author Message
 macro copying formula in active rows

I have a macro that adds up five columns of numbers using the following:

'  Calculate Total Hours
Range("X2").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-21]:RC[-17])"

Which works fine for the first row. I then need to copy this down the
sheet for all of the rows that contain data, which can be anything from
1 to thousands. I recall a thread about "Active Ranges" but I am not
sure how to apply this in this instance.

I have the following work around which works by copying the formular
down the entire column, then deleteing rows, based on whether a coulumn
is blank, but this is quite slow.
Range("X2").Select
Selection.Copy
Columns("X:X").Select
ActiveSheet.Paste
Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete (xlUp)

Any help and suggestions to speed this up would be greatly recieved.

Andy



Sat, 26 Jul 2003 00:39:27 GMT  
 macro copying formula in active rows
Suggest you post a small piece of the actual data to clarify.  Sounds
like an easy and faster solution will be quickly at hand.
Regards,


Quote:
> I have a macro that adds up five columns of numbers using the
following:

> '  Calculate Total Hours
> Range("X2").Select
> ActiveCell.FormulaR1C1 = "=SUM(RC[-21]:RC[-17])"

> Which works fine for the first row. I then need to copy this down the
> sheet for all of the rows that contain data, which can be anything
from
> 1 to thousands. I recall a thread about "Active Ranges" but I am not
> sure how to apply this in this instance.

> I have the following work around which works by copying the formular
> down the entire column, then deleteing rows, based on whether a
coulumn
> is blank, but this is quite slow.
> Range("X2").Select
> Selection.Copy
> Columns("X:X").Select
> ActiveSheet.Paste
> Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete (xlUp)

> Any help and suggestions to speed this up would be greatly recieved.

> Andy

--
Ctrl-Alt-Dlt-Hlp ?)?

Sent via Deja.com
http://www.deja.com/



Sat, 26 Jul 2003 02:47:45 GMT  
 macro copying formula in active rows
Andy

Are there any blank rows in your data?  If so, this will not work, otherwise
try this:

Range("X2",Range("Y2").End(xlDown).Offset(0,1)).FormulaR1C1 = "=SUM etc...

This assumes that column Y will contain information for each row that you
want to put this formula in.  If another column would be better, change the
"Y2" to whatever - then be sure to change the Offset to get back over to
column X.  It's generally not necessary to select a cell before you perform
some operation on it, so I combined your two statements in to one.

HTH
{*filter*} K.


Quote:
> I have a macro that adds up five columns of numbers using the following:

> '  Calculate Total Hours
> Range("X2").Select
> ActiveCell.FormulaR1C1 = "=SUM(RC[-21]:RC[-17])"

> Which works fine for the first row. I then need to copy this down the
> sheet for all of the rows that contain data, which can be anything from
> 1 to thousands. I recall a thread about "Active Ranges" but I am not
> sure how to apply this in this instance.

> I have the following work around which works by copying the formular
> down the entire column, then deleteing rows, based on whether a coulumn
> is blank, but this is quite slow.
> Range("X2").Select
> Selection.Copy
> Columns("X:X").Select
> ActiveSheet.Paste
> Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete (xlUp)

> Any help and suggestions to speed this up would be greatly recieved.

> Andy



Sat, 26 Jul 2003 07:33:54 GMT  
 macro copying formula in active rows
Andrew,

Why not just ActiveCell.FormulaR1C1 = "=SUM(C[-21]:C[-17])"
That way its sums up everything in those columns!

Michiel


Quote:
> I have a macro that adds up five columns of numbers using the following:

> '  Calculate Total Hours
> Range("X2").Select
> ActiveCell.FormulaR1C1 = "=SUM(RC[-21]:RC[-17])"

> Which works fine for the first row. I then need to copy this down the
> sheet for all of the rows that contain data, which can be anything from
> 1 to thousands. I recall a thread about "Active Ranges" but I am not
> sure how to apply this in this instance.

> I have the following work around which works by copying the formular
> down the entire column, then deleteing rows, based on whether a coulumn
> is blank, but this is quite slow.
> Range("X2").Select
> Selection.Copy
> Columns("X:X").Select
> ActiveSheet.Paste
> Columns("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete (xlUp)

> Any help and suggestions to speed this up would be greatly recieved.

> Andy



Tue, 29 Jul 2003 03:36:35 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. copying a formula down x rows one time then y rows the next time

2. Copying formula to new row only when data in previous row

3. Copy certain rows to active workbook not working

4. Copy certain rows to active workbook

5. Copying the active row

6. Macro command to find Active Row.

7. Active Cell for Add New Row Macro

8. Excel 7.0 Macro Formula to convert active cell to uppercase

9. Macro path doesn't point to currently active copy of file

10. Row insert and Formula copy problem


 
Powered by phpBB® Forum Software © phpBB Group