Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 23
Default hardcode a column in a formula

How do I hardcode a column in a formula? Currently I have the following but
I'd like want to modify the sum formula so that it sums the cells above minus
cell=C2, because 1st row is Headers? Is there any way to hard code the 2nd
part so that it's always subtracting from C2 and no other cells? I'd like it
so that it's always Column = C and Row = 2 that it subtracts from because the
number of columns changes in between column C and the last column depending
on the sheet.
lCol = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
With Cells(Rows.Count, lCol).End(xlUp)
.Offset(1, 0).FormulaR1C1 = _
"=SUM(R[-" & .Row - 1 & "]C:R[-1]C)-R[-" & .Row - 1 & "]C[-8]"
I would like to change C[-8] to be always Column C and not 8 columns to the
left of the cell with the formula. Any assistance would be appreciated.

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default hardcode a column in a formula

AHizon,

With Cells(Rows.Count, lCol).End(xlUp)
.Offset(1, 0).Formula = _
"=SUM(" & Range(Cells(2, lCol), .Cells(1, 1)).Address & ") - C2"
End With

HTH,
Bernie
MS Excel MVP


"AHizon via OfficeKB.com" <u38169@uwe wrote in message
news:79bf3150b0b50@uwe...
How do I hardcode a column in a formula? Currently I have the following
but
I'd like want to modify the sum formula so that it sums the cells above
minus
cell=C2, because 1st row is Headers? Is there any way to hard code the
2nd
part so that it's always subtracting from C2 and no other cells? I'd like
it
so that it's always Column = C and Row = 2 that it subtracts from because
the
number of columns changes in between column C and the last column
depending
on the sheet.
lCol = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
With Cells(Rows.Count, lCol).End(xlUp)
.Offset(1, 0).FormulaR1C1 = _
"=SUM(R[-" & .Row - 1 & "]C:R[-1]C)-R[-" & .Row - 1 & "]C[-8]"
I would like to change C[-8] to be always Column C and not 8 columns to
the
left of the cell with the formula. Any assistance would be appreciated.

--
Message posted via http://www.officekb.com



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 23
Default hardcode a column in a formula

That did the trick...Thanks so much!

Bernie Deitrick wrote:
AHizon,

With Cells(Rows.Count, lCol).End(xlUp)
.Offset(1, 0).Formula = _
"=SUM(" & Range(Cells(2, lCol), .Cells(1, 1)).Address & ") - C2"
End With

HTH,
Bernie
MS Excel MVP

How do I hardcode a column in a formula? Currently I have the following
but

[quoted text clipped - 18 lines]
the
left of the cell with the formula. Any assistance would be appreciated.


--
Message posted via http://www.officekb.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Month formula from column to column Jana Excel Discussion (Misc queries) 3 July 5th 07 03:10 PM
formula : =(column A)+(column B)-(column C). Why won't it work? Kristin Drover Excel Discussion (Misc queries) 3 October 18th 06 08:48 PM
Formula help for counting,with a column of dates and a column of n Altstatten Excel Worksheet Functions 2 December 8th 05 09:32 PM
column to column conditional formatting won't work, need formula rrupp Excel Worksheet Functions 1 August 23rd 05 10:06 PM
what formula do i put for column m = column k minus column l in e. jenniss Excel Discussion (Misc queries) 5 January 6th 05 08:18 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"