VBA for Summing a certain cell on multiple sheets

Dclarke

New Member
Joined
Sep 8, 2014
Messages
8
Hello,

I'm trying to figure out the VBA code to sum a certain cell on multiple sheets.

I've made a workbook to keep track of revenue for my job. I made a locked sheet where my team can enter the necessary information and then I added a button that will save this information onto a new tab and then reset the locked sheet for them to enter the next set of information.

The new tabs are named based on the information they enter into a certain cell on the locked tab. The locked tab is always the first tab. Because of this, i have no way of knowing what the new tabs will be named, as they will always be unique. Therefore I cannot just do a standard formula.

The number of tabs will also vary, but it should never exceed 15.

The cell that I would like to add will always be J27. I would like the VBA code to sum cell J27 from the first 15 tabs in the workbook. There may be less than 15, if that affects anything, but I need up to 15.

This will sum on to a summary tab that I have called "Monthly Tracker". I've put a button it for them to click to refresh the formula.

Any help would be appreciated. Sorry if this was confusing.

Thank you
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You can count the number of worksheets using:

Code:
ActiveWorkbook.Worksheets.Count

You can then create a loop to go through the sheets one by one adding the value from J27 to your total.
 
Upvote 0
Conceptually, I understand what you're saying. But today is basically my first day messing around with VBA.

I don't know how to loop into a sum formula. Sorry!
 
Upvote 0
See if the below makes sense to you:

Code:
Private Sub CommandButton1_Click()

Dim i As Long
Dim x As Long

x = 0

For i = 1 To ActiveWorkbook.Worksheets.Count

    x = x + Sheets(i).Range("J27").Value2
    
Next i

Sheet1.Range("A1").Value2 = x

End Sub
 
Last edited:
Upvote 0
Actually, I realized that my first and last tab are always the same no matter what. So I just did a standard sum formula for the range of worksheets FirstSheet:LastSheetJ27 and it works.

I do appreciate the help though! I was overthinking here
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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