Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default trying to insert a formula

I'm trying to put a formula in a cell that sums from the row
immediately above to a row whose number I saved previously as a
variable (lPrevSumRow):

With ActiveSheet
.Cells(lNextRow, "H") = "Totals"
.Cells(lNextRow, "I").Formula = "=Sum(.Cells(lNextRow - 1,
9).Cells(lPrevSumRow, 9))"

End With

I have figured out the putting the formula in quotes isn't working
because I'm getting an error on the Sum function. XL isn't recognizing
the (.cells(lNextRow....) while it's in quotes. Is there anyway to
insert the formula with the range to be summed as a variable rather
than actual cell addresses?

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default trying to insert a formula

i set the variables because i didn't know what yours were

With ActiveSheet
lPrevSumRow = 1
lNextRow = 15
.Cells(lNextRow, "H") = "Totals"
.Cells(lNextRow, "I").Formula = "=Sum(i" & lPrevSumRow & ":" &
"i" _
& lNextRow - 1 & ")"
End With
--


Gary

"davegb" wrote in message
oups.com...
I'm trying to put a formula in a cell that sums from the row
immediately above to a row whose number I saved previously as a
variable (lPrevSumRow):

With ActiveSheet
.Cells(lNextRow, "H") = "Totals"
.Cells(lNextRow, "I").Formula = "=Sum(.Cells(lNextRow - 1,
9).Cells(lPrevSumRow, 9))"

End With

I have figured out the putting the formula in quotes isn't working
because I'm getting an error on the Sum function. XL isn't recognizing
the (.cells(lNextRow....) while it's in quotes. Is there anyway to
insert the formula with the range to be summed as a variable rather
than actual cell addresses?

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default trying to insert a formula

watch the word wrap and the underscores (there aren't any in the formulas) ,
i used vista to post this and windows mail isn't too polished yet.

..Cells(lNextRow, "I").Formula = "=Sum(i" & lPrevSumRow & ":" & "i" &
lNextRow - 1 & ")".Cells(lNextRow, "I").Formula = "=Sum(i" & lPrevSumRow &
":" & "i" & lNextRow - 1 & ")"
--


Gary

"Gary Keramidas" wrote in message
...
i set the variables because i didn't know what yours were

With ActiveSheet
lPrevSumRow = 1
lNextRow = 15
.Cells(lNextRow, "H") = "Totals"
.Cells(lNextRow, "I").Formula = "=Sum(i" & lPrevSumRow & ":" &
"i" _
& lNextRow - 1 & ")"
End With
--


Gary

"davegb" wrote in message
oups.com...
I'm trying to put a formula in a cell that sums from the row
immediately above to a row whose number I saved previously as a
variable (lPrevSumRow):

With ActiveSheet
.Cells(lNextRow, "H") = "Totals"
.Cells(lNextRow, "I").Formula = "=Sum(.Cells(lNextRow - 1,
9).Cells(lPrevSumRow, 9))"

End With

I have figured out the putting the formula in quotes isn't working
because I'm getting an error on the Sum function. XL isn't recognizing
the (.cells(lNextRow....) while it's in quotes. Is there anyway to
insert the formula with the range to be summed as a variable rather
than actual cell addresses?

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default trying to insert a formula


Gary Keramidas wrote:
watch the word wrap and the underscores (there aren't any in the formulas) ,
i used vista to post this and windows mail isn't too polished yet.

.Cells(lNextRow, "I").Formula = "=Sum(i" & lPrevSumRow & ":" & "i" &
lNextRow - 1 & ")".Cells(lNextRow, "I").Formula = "=Sum(i" & lPrevSumRow &
":" & "i" & lNextRow - 1 & ")"
--


Gary

"Gary Keramidas" wrote in message
...
i set the variables because i didn't know what yours were

With ActiveSheet
lPrevSumRow = 1
lNextRow = 15
.Cells(lNextRow, "H") = "Totals"
.Cells(lNextRow, "I").Formula = "=Sum(i" & lPrevSumRow & ":" &
"i" _
& lNextRow - 1 & ")"
End With
--


Gary


The one above worked. The second one you submitted didn't. Not sure why
you had .formula in it twice, maybe a pasting mistake?

I made one small change. Where you had &":"&"i", I replaced with &":i".

Thanks for the help!


"davegb" wrote in message
oups.com...
I'm trying to put a formula in a cell that sums from the row
immediately above to a row whose number I saved previously as a
variable (lPrevSumRow):

With ActiveSheet
.Cells(lNextRow, "H") = "Totals"
.Cells(lNextRow, "I").Formula = "=Sum(.Cells(lNextRow - 1,
9).Cells(lPrevSumRow, 9))"

End With

I have figured out the putting the formula in quotes isn't working
because I'm getting an error on the Sum function. XL isn't recognizing
the (.cells(lNextRow....) while it's in quotes. Is there anyway to
insert the formula with the range to be summed as a variable rather
than actual cell addresses?

Thanks!



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
how to insert a formula? JoeF Excel Discussion (Misc queries) 4 November 29th 09 04:38 AM
insert formula [email protected] Excel Worksheet Functions 0 May 17th 06 12:45 PM
How to insert = in formula bar Tirtha Raj Adhikari Excel Discussion (Misc queries) 1 September 14th 05 09:02 AM
insert formula [email protected] Excel Programming 1 August 16th 05 07:27 PM
insert a new row by formula Doug Excel Worksheet Functions 3 November 18th 04 12:28 PM


All times are GMT +1. The time now is 04:26 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"