entering formulas on a sheet

S

stu

Hi

I have a sheet which is created from a search of a much larger sheet. the
number of rows can vary from 1 to XXX. I would like to do a sum of the
columns and have it placed on the next empty row. I have tried using the
..formula = "=sum(c3:C"+variable+")" in a loop but just get mismatch errors.
any help would be gratefully appreciated.

Regards

Stu
 
S

stu

It doesn't matter where I put it. The problem I am having is getting the
formula =sum(c3:CXXX) where for that column XXX is unknown until the sheet
has been created by a search and copy/paste macro.

Stuart
 
T

Tom Ogilvy

sub SetupSums()
Dim rng as Range
for i = 1 to 10
set rng = cells(rows.count,i).End(xlup)(2)
rng.FormulaR1C1 = "=Sum(R3C:R[-1]C)"
Next
End Sub

change 10 to the number of columns to process.
 
S

stu

Many thanks would not of got it in a million years.
Been trying to solve it for a few days now.

Thanks

Stuart



Tom Ogilvy said:
sub SetupSums()
Dim rng as Range
for i = 1 to 10
set rng = cells(rows.count,i).End(xlup)(2)
rng.FormulaR1C1 = "=Sum(R3C:R[-1]C)"
Next
End Sub

change 10 to the number of columns to process.


stu said:
Hi

I have a sheet which is created from a search of a much larger sheet. the
number of rows can vary from 1 to XXX. I would like to do a sum of the
columns and have it placed on the next empty row. I have tried using the
.formula = "=sum(c3:C"+variable+")" in a loop but just get mismatch errors.
any help would be gratefully appreciated.

Regards

Stu
 
T

Tom Ogilvy

if you want it at the top, then you don't care where the bottom is

Range("A1:M1").Formula = "=Sum(A3:A65536)"
 
Top