vba code for multiple non continuous range in a column

kishorvimal

New Member
Joined
May 28, 2011
Messages
25
Hi,

Can some one help me with VBA code for getting sum in multiple range in a column.

I have numeric values in column B like B2 and B3 have some values and B4 and B5 are blank then B6, B7 and B8 have some values and B9 and B10 are blank. So, I want sum of B1 and B2 in B3 and sum of B6, B7 and B8 in B9 cell and same macro should work for this trend of sum in continuous filled multiple ranges in B column.

Many thanks in advance.


Vimal
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Is it something like this that you want? (run code)
Code:
Sub sumnoncontig()
Dim e As Range
Set e = Range("B1")
If e = "" Then Set e = e.End(4)
Do
If e(2) = "" Then
    e.Offset(, 1) = e
    Set e = e.End(4)
Else
    e.End(4).Offset(, 1) = Application.Sum(Range(e, e.End(4)))
    Set e = e.End(4).End(4)
End If
Loop Until e.Row = Rows.Count
End Sub
 
Upvote 0
Thanks for the quick response. Actually I have basic knowledge of VBA. I want sum on 3rd, 9th and 12th cell in B column

Column
Row B
1 15
2 14
3 ---
5 ---
6 35
7 45
8 24
9 ---
10 ---
11 45
12 ---
13 ---




Thanks in advance....

Vimal
 
Upvote 0
This one?
Code:
Sub sumnoncontig2()
Dim e As Range, x, y As Single
Set e = Range("B1")
If e = "" Then Set e = e.End(4)
Do
If e(2) = "" Then
    Set e = e.End(4)
Else
    x = e.End(4)(2).Address
    y = Application.Sum(Range(e, e.End(4)))
    Set e = e.End(4).End(4)
    Range(x) = y
End If
Loop Until e.Row = Rows.Count
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top