Button to sum numbers and update a running total

NewCoder1

New Member
Joined
Jul 28, 2023
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi All,

I am getting an out of range error on the below green and bold line. I am attaching the Sub to a button to call it. Does anyone know why this error is coming up? There is a value in the sheet and within the cell.

Sub AddNumbersFromSheets()
Dim valueFromSheet1 As Double
Dim valueFromSheet3 As Double
Dim Total As Double
valueFromSheet1 = CDbl(Sheets("Sheet1").Range("E10").Value)
valueFromSheet3 = CDbl(Sheets("Sheet3").Range("C5").Value)
Total = valueFromSheet1 + valueFromSheet3
Worksheets(Sheet3).Range("C5").Value = Total
MsgBox "Thank you"
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Welcome to the Board!

Do you have a sheet named "Sheet1"?
What exactly is in cell E10 of this sheet?
 
Upvote 0
Welcome to the Board!

Do you have a sheet named "Sheet1"?
What exactly is in cell E10 of this sheet?
Hi and thank you.

The sheet is called "Dashboard" but still shows as "Sheet1 (Dashboard)" in the VBA editor.

Within E10 is a number which is the result of a simple sum of 2 cells.
 
Upvote 0
The sheet is called "Dashboard" but still shows as "Sheet1 (Dashboard)" in the VBA editor.
Then you are referring to the sheet name incorrectly.

It should be:
valueFromSheet1 = CDbl(Sheets("Dashboard").Range("E10").Value)
or:
valueFromSheet1 = CDbl(Sheet1.Range("E10").Value)
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,734
Members
452,939
Latest member
WCrawford

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