Autosum & Msgbox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I have this code supplied below in place but need advice please.

I would like to include the autosum shown below into it.

Worksheet is called DATABASE
The range would be O5:O179

As info is added to the DATABASE worksheet the 179 then becomes 180,181,182 etc etc

Many thanks.


Code:
Private Sub BalanceSoFar_Click()MsgBox "Earnings To Date " & Format(Worksheets("DATABASE").Range("A1").Value, "£0.00")
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,

Try to use the following code:

Code:
Private Sub BalanceSoFar_Click()
    Dim lngLastRow          As Long
    Dim lngSumValues        As Long
    
    With Sheets("DATABASE")
        lngLastRow = .Cells(.Rows.Count, "O").End(xlUp).Row
        lngSumValue = Application.WorksheetFunction.Sum(Range("O5:O" & lngLastRow))
    End With
    
    MsgBox "Earnings To Date " & Format(lngSumValue, "£0.00")


End Sub
 
Upvote 0
Hi,

Try to use the following code:

Code:
Private Sub BalanceSoFar_Click()
    Dim lngLastRow          As Long
    Dim lngSumValues        As Long
    
    With Sheets("DATABASE")
        lngLastRow = .Cells(.Rows.Count, "O").End(xlUp).Row
        lngSumValue = Application.WorksheetFunction.Sum(Range("O5:O" & lngLastRow))
    End With
    
    MsgBox "Earnings To Date " & Format(lngSumValue, "£0.00")


End Sub


Hi,
I spoke too son.

I have check the sheet name & cell range of which is correct.

When the code is run it returns £0.00

I then tried it out with a run on the same sheet etc but still returns £0.00

Do you see a reason why ???
 
Upvote 0
Check that your numbers are actually numbers & not text.
In a blank cell enter =ISNUMBER(O6) What does it say?
 
Upvote 0
What is the value in O6?
 
Upvote 0
Fluff,

Please use the code supplied on a new excel sheet & see if you also get £0.00
 
Upvote 0
There's nothing wrong with the code, that's why I was asking if your numbers were true numbers.
I cannot think of any reason why the code would give £0.00
That said as you are using decimals I'd make this change
Code:
Dim lngSumValues        As Double
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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