Sum Blank

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Hello All

Trying to sum range above when cell is Blank. Using the below code.

Code:
Sub SumBlank()Dim lr&
Dim i&
lr = Cells(Rows.Count, 1).End(xlUp).Row
total = 0


With ActiveSheet
For i = 1 To lr + 1
If Cells(i, 1) <> "" Then
total = total + Cells(i, 1)
End If
Next
End With
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
What exactly is your question?
 
Upvote 0
Looking to insert the sum of the above in the blank cells.

Thank You

[TABLE="class: outer_border, width: 500, align: center"]
<tbody>[TR]
[TD]12
[/TD]
[/TR]
[TR]
[TD]12[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]20[/TD]
[/TR]
[TR]
[TD]35[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]230[/TD]
[/TR]
[TR]
[TD]120[/TD]
[/TR]
[TR]
[TD]250[/TD]
[/TR]
[TR]
[TD]125[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Maybe
Code:
Sub SumBlank()
Dim lr As Long, i As Long
Dim total As Double
lr = Cells(Rows.Count, 1).End(xlUp).Row
total = 0


With ActiveSheet
   For i = 1 To lr + 1
      If .Cells(i, 1) <> "" Then
         total = total + .Cells(i, 1)
      Else
         .Cells(i, 1) = total
         total = 0
      End If
   Next i
End With
End Sub
 
Upvote 0
Hi,

You could use an Array Formula in cell B2 :

Code:
=IF(A2="",IFERROR(1/(1/SUM(A2:INDEX(A$1:A1,MATCH(9.99999999999999E+307,1/(1-ISNUMBER(A$1:A1)))))),""),"")

HTH
 
Upvote 0
Assuming your numerical values are constants (that is, that they are not the result of formulas in the cells), give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub SumToBlanks()
  Dim Ar As Range
  For Each Ar In Columns("A").SpecialCells(xlConstants).Areas
    Ar(1).Offset(Ar.Count).Value = Application.Sum(Ar)
  Next
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
@ Fluff Works perfect. Why is there a need to include an else.

@ Mr. Rothstein. Missed this one - using the SpecialCells Method is also adequate.

Thank you
 
Upvote 0
James

Thank You for the formula option, however the first two cells in the range are not totaled using this method.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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