Putting formula in cells from a loop

A

Andreww

Hi - I want to put formulae in cells in my worksheet based on
itterating values.

For instance:

=sum("A2")
=sum("A3")
=sum("A4")
=sum("A5")

The way I thought to do it was from this loop

For ii = 1 To 5
Sheets("detail").Range("E" & Trim(Str(ii))).Formula =
"=sum(""A""&ltrim(str(ii)))"
Next ii

Whatever I try I get #NAME? in the cells on the worksheet.

Tried changing quotes, putting ampersands in etc.

Any ideas?

Thanks

Andrew
 
P

Peter T

Hi Andrew,

change
= "=sum(""A""&ltrim(str(ii)))"
to
= "=sum(A" & Trim(Str(ii)) & ")"

or simply
= "=sum(A" & ii & ")"

you don't need the other Trim(Str(ii)) either

Regards,
Peter T
 

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