Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default sum variable # of rows

I am writing some code to clean up data I imported into excel. I will have a
vraiable number of rows each time I run the macro.

Always in Coulmn B is the number I want to sum. What function can I use to
count the number of rows I have & then put the sum of Column B in the next
free row. i.e.

Rows 1-5 have data , put sum of B1:B5 into B6 where next time it could be
B1:B10 sum in B11.

Thank you.
Regard,
Diane
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default sum variable # of rows

Hi,
Try this:

Dim lRow As Long

Const Formula As String = "=sum(b1:bX)"

lRow = Cells(Rows.Count, "B").End(xlUp).Row ' find last row in colum b

Cells(lRow + 1, "B") = Application.Substitute(Formula, "X", lRow) '
substitute X by lrow in SUM formula


HTH
"Diane" wrote:

I am writing some code to clean up data I imported into excel. I will have a
vraiable number of rows each time I run the macro.

Always in Coulmn B is the number I want to sum. What function can I use to
count the number of rows I have & then put the sum of Column B in the next
free row. i.e.

Rows 1-5 have data , put sum of B1:B5 into B6 where next time it could be
B1:B10 sum in B11.

Thank you.
Regard,
Diane

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default sum variable # of rows

The following puts the formula into the last cell in column B + 1

Cells(Cells(65336, "B").End(xlUp).Row + 1, 2) = "=SUM(B1:B" & Cells(65536,
"B").End(xlUp).Row & ")"


--
Cheers
Nigel



"Diane" wrote in message
...
I am writing some code to clean up data I imported into excel. I will have

a
vraiable number of rows each time I run the macro.

Always in Coulmn B is the number I want to sum. What function can I use

to
count the number of rows I have & then put the sum of Column B in the next
free row. i.e.

Rows 1-5 have data , put sum of B1:B5 into B6 where next time it could be
B1:B10 sum in B11.

Thank you.
Regard,
Diane



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default sum variable # of rows

As you ask in programming, I assume you want VBA

iLastRow = Cells(Rows.Count,"B").End(xlUp).Row
Cell(iLastRow+1,"B").Formula = "SUM(B1:B" & iLastRow & ")"

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Diane" wrote in message
...
I am writing some code to clean up data I imported into excel. I will have

a
vraiable number of rows each time I run the macro.

Always in Coulmn B is the number I want to sum. What function can I use

to
count the number of rows I have & then put the sum of Column B in the next
free row. i.e.

Rows 1-5 have data , put sum of B1:B5 into B6 where next time it could be
B1:B10 sum in B11.

Thank you.
Regard,
Diane



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default sum variable # of rows

One Mo

cells(rows.count,"B").End(xlup)(2).FormulaR1C1 = "=Sum(R1C:R[-1]C)"

--
Regards,
Tom Ogilvy


"Diane" wrote in message
...
I am writing some code to clean up data I imported into excel. I will have

a
vraiable number of rows each time I run the macro.

Always in Coulmn B is the number I want to sum. What function can I use

to
count the number of rows I have & then put the sum of Column B in the next
free row. i.e.

Rows 1-5 have data , put sum of B1:B5 into B6 where next time it could be
B1:B10 sum in B11.

Thank you.
Regard,
Diane



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
HLOOKUP with variable rows Max Excel Discussion (Misc queries) 2 February 25th 09 08:00 AM
sum and variable rows Jim Excel Worksheet Functions 4 September 7th 05 07:48 PM
Using Variable in Rows(x:y) function tedpeterborough Excel Programming 2 August 2nd 04 09:29 PM
macro with variable rows Annelie[_5_] Excel Programming 3 May 16th 04 02:14 PM
Selecting rows with variable Jim[_24_] Excel Programming 7 September 16th 03 02:03 PM


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