Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Add cells between blank cells

I have numbers in cells I2:I20, cell I21 is blank and then more numbers in
cells I22:I30 and I31 is blank. This will repeat down the sheet. I would
like a formula in column J to sum all the numbers in between the blank cells.
In cell J20 I would like it to sum cells I2:I20, in cell J30 sum cells
I22:I30, etc. I know I can go to those cells and enter the sum equation but
is there something I can copy down the sheet? Let me know if you don't
understand and I will try to rephrase the question. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Add cells between blank cells

Sub AddFormulas()
j = Cells(Rows.Count, "I").End(xlUp).Row + 1
k = 2
For i = 1 To j
If Cells(i, "I").Value = "" Then
Cells(i, "J").Formula = "=SUM(I" & k & ":I" & i - 1 & ")"
k = i + 1
End If
Next
End Sub


Macros are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To use the macro from the normal Excel window:

1. ALT-F8
2. Select the macro
3. Touch Run



To remove the macro:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


--
Gary''s Student - gsnu200856


"Jambruins" wrote:

I have numbers in cells I2:I20, cell I21 is blank and then more numbers in
cells I22:I30 and I31 is blank. This will repeat down the sheet. I would
like a formula in column J to sum all the numbers in between the blank cells.
In cell J20 I would like it to sum cells I2:I20, in cell J30 sum cells
I22:I30, etc. I know I can go to those cells and enter the sum equation but
is there something I can copy down the sheet? Let me know if you don't
understand and I will try to rephrase the question. Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,549
Default Add cells between blank cells

Enter in J2 and fill down...
=IF(ISBLANK(I2),SUM($I$2:I2)-SUM($J$1:OFFSET($J$1,ROW()-2,0)),"")
--
Jim Cone
Portland, Oregon USA



"Jambruins"
wrote in message
I have numbers in cells I2:I20, cell I21 is blank and then more numbers in
cells I22:I30 and I31 is blank. This will repeat down the sheet. I would
like a formula in column J to sum all the numbers in between the blank cells.
In cell J20 I would like it to sum cells I2:I20, in cell J30 sum cells
I22:I30, etc. I know I can go to those cells and enter the sum equation but
is there something I can copy down the sheet? Let me know if you don't
understand and I will try to rephrase the question. Thanks.
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Add cells between blank cells

thank you

"Jim Cone" wrote:

Enter in J2 and fill down...
=IF(ISBLANK(I2),SUM($I$2:I2)-SUM($J$1:OFFSET($J$1,ROW()-2,0)),"")
--
Jim Cone
Portland, Oregon USA



"Jambruins"
wrote in message
I have numbers in cells I2:I20, cell I21 is blank and then more numbers in
cells I22:I30 and I31 is blank. This will repeat down the sheet. I would
like a formula in column J to sum all the numbers in between the blank cells.
In cell J20 I would like it to sum cells I2:I20, in cell J30 sum cells
I22:I30, etc. I know I can go to those cells and enter the sum equation but
is there something I can copy down the sheet? Let me know if you don't
understand and I will try to rephrase the question. Thanks.

  #5   Report Post  
Junior Member
 
Posts: 1
Default

Quote:
Originally Posted by Gary''s Student View Post
Sub AddFormulas()
j = Cells(Rows.Count, "I").End(xlUp).Row + 1
k = 2
For i = 1 To j
If Cells(i, "I").Value = "" Then
Cells(i, "J").Formula = "=SUM(I" & k & ":I" & i - 1 & ")"
k = i + 1
End If
Next
End Sub


Macros are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To use the macro from the normal Excel window:

1. ALT-F8
2. Select the macro
3. Touch Run



To remove the macro:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


--
Gary''s Student - gsnu200856


"Jambruins" wrote:

I have numbers in cells I2:I20, cell I21 is blank and then more numbers in
cells I22:I30 and I31 is blank. This will repeat down the sheet. I would
like a formula in column J to sum all the numbers in between the blank cells.
In cell J20 I would like it to sum cells I2:I20, in cell J30 sum cells
I22:I30, etc. I know I can go to those cells and enter the sum equation but
is there something I can copy down the sheet? Let me know if you don't
understand and I will try to rephrase the question. Thanks.
I tried this but the total shows in cell j21 or j31 rather than j20 or j30.. Is there an adjustment that I can make to this vb code to make that occur?

thx...

Snowiii33
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
zero value cells/blank cells causing error in AVERAGE? LilBeanie1033 Excel Worksheet Functions 5 March 19th 09 06:39 PM
Range naming cells with blank cells through coding Naveen J V Excel Discussion (Misc queries) 1 March 27th 08 01:46 PM
Maximum Number of Blank Cells between Non Blank Cells in a Range Mal Excel Worksheet Functions 5 November 3rd 07 08:21 AM
Excel inserted 0's in cells linked to blank cells lburg801 Excel Discussion (Misc queries) 5 October 28th 05 11:32 PM
How do I skip blank cells when copying over a range of cells? tawells Excel Discussion (Misc queries) 2 June 7th 05 09:36 PM


All times are GMT +1. The time now is 01:27 AM.

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"