View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
leung leung is offline
external usenet poster
 
Posts: 119
Default Better Understanding

the formula for this
"=SUM(C[-2])"
will be changed to =SUM(A:A)
when you run the code.


but that depends where your cell is 'active' as you are in the cell in
colume C, because Range("C1") is just selected then the C[-2] will point to
Column A:A , if you put C[+2] then the formula will be "=SUM(E:E)" .

if you don't want the formula depend on the location then you just simply
put =sum(A:A), this case won't depend on the active cell.


another point is that, sometime selecting the cell is not necessary. For
example

Range("G1").select
selection.formula = "=$A$10"

then you can simply it to:
Range("G1").formula = "=$A$10"

the this new line of code won't move the active cell at all and sometims
simplying the code is the first step of learning from macro to VBA coding.






"Marsh" wrote:

I am in the process of beginning to teach myself VBA for Excel 2007. The
primer I am using starts with recording macros, editing recorded macros, and
eventually moves on to writing code from scratch.
Question, I recorded a macro where I put a formula =sum(A:A) into cell C1.
The recorder coded this formula to
Range("C1").Select
ActiveCell.FormulaR1C1 = "=SUM(C[-2])"
I am not sure I understand the syntax of the sum function. I do believe it
is indicating to select data 2 columns tot he left of column C, but does it
assume the data populates all cells that column, in this example column A.