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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
What exactly is your question?
 
Upvote 0
Looking to insert the sum of the above in the blank cells.

Thank You

12
12
20
35
230
120
250
125

<tbody>
</tbody>
 
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,214,402
Messages
6,119,304
Members
448,886
Latest member
GBCTeacher

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