PC Review


Reply
Thread Tools Rate Thread

Create sum formula when using index column/row references

 
 
=?Utf-8?B?U3R1IFc=?=
Guest
Posts: n/a
 
      27th May 2007
I've got a program that I've created in Excel using VBA. I'm creating some
calculations from sheets that are imported from elsewhere. I'm needing to
create a sum formula on the worksheet. The column and row reference for
where this formula will be placed will differ by worksheet. I'm using some
variables like mCol and mRow to keep track of which column and row I'm doing
stuff on. These variables are tracking the column and row reference by index
number, not by the letter identifier of the column.

Now, I'm at the point where I'm having to place a sum function in a cell,
except that I need the sum function to add up all of the cells above it. So,
for example, if the sum formula goes into C25, I want it to place a formula
that will go into cell C25, something like sum(c1:c24). But I'm using index
numbers instead of column letters to track which column I'm doing this in.
So, mCol = 3 and mRow = 25.

I can't figure out how to construct the sum formula using my index variables.


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      27th May 2007
One way is to use .formulaR1C1 and you don't have to worry about much:

with worksheets("sheet999")
.cells(mrow,mcol).formular1c1 = "=sum(r1c:r[-1]c)"
end with

R1C means row 1 of the same column.
r[-1]c means the row above in the same column

But if you wanted:

with worksheets("sheet999")
.cells(mrow,mcol).formula _
= "=sum(" & .range(.cells(1,mcol),.cells(mrow-1,mcol)).address & ")"
end with


Stu W wrote:
>
> I've got a program that I've created in Excel using VBA. I'm creating some
> calculations from sheets that are imported from elsewhere. I'm needing to
> create a sum formula on the worksheet. The column and row reference for
> where this formula will be placed will differ by worksheet. I'm using some
> variables like mCol and mRow to keep track of which column and row I'm doing
> stuff on. These variables are tracking the column and row reference by index
> number, not by the letter identifier of the column.
>
> Now, I'm at the point where I'm having to place a sum function in a cell,
> except that I need the sum function to add up all of the cells above it. So,
> for example, if the sum formula goes into C25, I want it to place a formula
> that will go into cell C25, something like sum(c1:c24). But I'm using index
> numbers instead of column letters to track which column I'm doing this in.
> So, mCol = 3 and mRow = 25.
>
> I can't figure out how to construct the sum formula using my index variables.


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?U3R1IFc=?=
Guest
Posts: n/a
 
      27th May 2007
Thanks, Dave. Worked perfectly. This forum is always a great resource.
Much appreciate the help.


"Dave Peterson" wrote:

> One way is to use .formulaR1C1 and you don't have to worry about much:
>
> with worksheets("sheet999")
> .cells(mrow,mcol).formular1c1 = "=sum(r1c:r[-1]c)"
> end with
>
> R1C means row 1 of the same column.
> r[-1]c means the row above in the same column
>
> But if you wanted:
>
> with worksheets("sheet999")
> .cells(mrow,mcol).formula _
> = "=sum(" & .range(.cells(1,mcol),.cells(mrow-1,mcol)).address & ")"
> end with
>
>
> Stu W wrote:
> >
> > I've got a program that I've created in Excel using VBA. I'm creating some
> > calculations from sheets that are imported from elsewhere. I'm needing to
> > create a sum formula on the worksheet. The column and row reference for
> > where this formula will be placed will differ by worksheet. I'm using some
> > variables like mCol and mRow to keep track of which column and row I'm doing
> > stuff on. These variables are tracking the column and row reference by index
> > number, not by the letter identifier of the column.
> >
> > Now, I'm at the point where I'm having to place a sum function in a cell,
> > except that I need the sum function to add up all of the cells above it. So,
> > for example, if the sum formula goes into C25, I want it to place a formula
> > that will go into cell C25, something like sum(c1:c24). But I'm using index
> > numbers instead of column letters to track which column I'm doing this in.
> > So, mCol = 3 and mRow = 25.
> >
> > I can't figure out how to construct the sum formula using my index variables.

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create index that references field - not page number CSWolfe Microsoft Word Document Management 1 24th Mar 2009 10:05 AM
Create see and see also references in an index? =?Utf-8?B?RHVjaGVzc2U=?= Microsoft Word Document Management 2 1st Apr 2008 09:34 PM
Creating a formula that references the last value of a column =?Utf-8?B?Y29ubnk=?= Microsoft Excel Misc 10 25th Jun 2007 01:12 AM
copy formula down a column and have cell references change within formula brad Microsoft Excel New Users 5 13th May 2007 04:38 PM
Incrementing Column references in a formula Randy Hunt Microsoft Excel Misc 1 9th Oct 2003 09:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:29 PM.