Autosum & Msgbox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
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
 
Sorry to say its still the same.
I will drop this now as taking up too much time.

Many thanks anyway.

Did you see the post today where it was mentioned that you dont download from the internet ?
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Just an update,

If i use the below it returns correctly.
Code:
=SUM(DATABASE!O6:O179)

If however i use this then it fails
Code:
=SUM(DATABASE!O6:O)
 
Last edited:
Upvote 0
If however i use this then it fails
Code:
=SUM(DATABASE!O5:O)

Why would you expect that to work without an end row number?
 
Upvote 0
My first post showed O179 but then if you look at post 2 i then went from there.
 
Upvote 0
My first post showed O179 but then if you look at post 2 i then went from there.

The codes suggested to you used lngLastRow as a variable number for the last used row

Code:
(Range("O5:O" & lngLastRow))

In your post number 12 you are omitting it so the question remains why you think it should work without an end row number?

I would check with the code JustynaMK posted what lngLastRow is returning judging by your last statement as you probably need to get the last row from another column.
 
Last edited:
Upvote 0
@ipbr21054, what happens with the code below?

Code:
Private Sub BalanceSoFar_Click()
    Dim lngLastRow          As Long
    Dim lngSumValues        As Double
    
    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
 
Last edited:
Upvote 0
You're welcome. Just so you know the sum was missing a period/fullstop before the Range so it wasn't linked to the with statement so unless Sheets("DATABASE") was the activesheet you would get the error.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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