Autosum Formila IN CELL ISSUES

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
I select cell D31
I then type =SUM(D5:D30) & hit enter.
Cell D31 shows £0.00 but address / forula bar shows 0 as opposed =SUM(D5:D30)
My values are not adding up in cells D5 to D30 because of this.
The cells are formatted as Currency

Please advise how it can stay there & add up the values
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
@Joe4 - only if you change the if statement to this:
VBA Code:
        If (Range("D31") = "") Or (Range("E31") = "") Then
Alex,

If you remember your high school logic class, you will recall that:
VBA Code:
If (Range("D31") = "") Or (Range("E31") = "")
(what you posted above)
is equivalent to:
VBA Code:
If (Range("D31") <> "") And (Range("E31") <> "")
(what I used in my last code)

Think about it.
"If either one is blank"
is the same as:
"If both are NOT blank"
 
Upvote 0
Ref Post#5
Does E5:E30 is formatted as text.
If the SUM formula is working for them, then they are clearly not text values being entered.
If the SUM formula returns zero, then that would suggest that.

I think the bigger issue is that the code they were originally using was not being triggered on updates to column E.
 
Upvote 0
A poor choice of words on my part. I should have said:
which only will update D31 and E31 if the either one is currently blank.
which more accurately describes what is going on.

However, I also did want to point out that the code revision you posted did not change anything - it does the exact same thing my code there does.
So, I think it was really my poor explanation that you probably had problems with, and not the code itself!
 
Upvote 0
@ipbr21054
If you were going to use the code in Post #16 here is a revised version.
It contains a correction to the If statement so that it only adds the formulas if there is currently no formula in either D31 or E31 and turns off/on enable events to stop it calling itself.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim Cell As Range
    
'CODE BLOCK 1: Watch columns B and C for updates
    Set rng = Intersect(Target, Range("B3:C" & Rows.Count))
    
'   If an update is made to the range
    If Not rng Is Nothing Then
    
'       Loop through all cells in our tar7get range
        Application.EnableEvents = False
        For Each Cell In rng
            Cell = UCase(Cell)
        Next Cell
        Application.EnableEvents = True
    End If
    
'CODE BLOCK 2: Watch columns D and E for updates
    If Not Intersect(Target, Range("D5:E30")) Is Nothing Then
        If (Range("D31").HasFormula = False) Or (Range("E31").HasFormula = False) Then
            Application.EnableEvents = False
            Range("D31:E31").FormulaR1C1 = "=SUM(R[-26]C:R[-1]C)"
            Application.EnableEvents = True
        End If
    End If
    
End Sub
 
Upvote 0
@ipbr21054
If you were going to use the code in Post #16 here is a revised version.
It contains a correction to the If statement so that it only adds the formulas if there is currently no formula in either D31 or E31 and turns off/on enable events to stop it calling itself.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim Cell As Range
   
'CODE BLOCK 1: Watch columns B and C for updates
    Set rng = Intersect(Target, Range("B3:C" & Rows.Count))
   
'   If an update is made to the range
    If Not rng Is Nothing Then
   
'       Loop through all cells in our tar7get range
        Application.EnableEvents = False
        For Each Cell In rng
            Cell = UCase(Cell)
        Next Cell
        Application.EnableEvents = True
    End If
   
'CODE BLOCK 2: Watch columns D and E for updates
    If Not Intersect(Target, Range("D5:E30")) Is Nothing Then
        If (Range("D31").HasFormula = False) Or (Range("E31").HasFormula = False) Then
            Application.EnableEvents = False
            Range("D31:E31").FormulaR1C1 = "=SUM(R[-26]C:R[-1]C)"
            Application.EnableEvents = True
        End If
    End If
   
End Sub
Excellent updates, Alex!

I am in agrrement that if they do require the second block, this is the best code to use yet!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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