Referring to a column

H

Hru48

Hey all,

I have a worksheet which has two columns to it and I need a third t
act as a totals column for all the values in columns a and b.

I'm doing it as part of a sub in vba and I need to know if there is
short way of reffering to column as I keep ending up with pages of:

Range("G3").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"
Columns("E:G").Select
Range("G4").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"
Columns("E:G").Select
Range("G5").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"

Many thanks
 
V

vezerid

Use these two snippets in your code. The dim statement comes after Sub.
The for...next statement goes wherever necessary. Modify
range("G2:G100") as necessary.

dim c as range

for each c in range("G2:G1000").cells
c.formular1c1="=SUM(RC[-2]:RC[-1])"
next c

HTH
Kostis Vezerides
 

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

Similar Threads

Macro Loop 1
Macro Flexability 7
Summing two columns 3
Macro from cell specific to whole column 4
Hard reference in a macro 1
Formula to sum rows 5
Macro Question formula 8
Macro - very slow run in 2003 3

Top