SUM same cell range across different sheets

glottis

New Member
Joined
Oct 21, 2011
Messages
11
Hello,

as per title I want to create a new sheet in my workbook and in this new sheets adding cells that are the sum of the cells of the previous 3 sheets but the cycle for doesn't run. This is what I wrote:

VBA Code:
  Set wdExl = Workbooks.Open(xlFileName) 'open Excel file
            
              AFO = wbNew3.Worksheets(1).Range("B11").Value
             MsgBox ("Variable = " & AFO)
        
        
  Dim SheetOne As Integer
  Dim SheetTwo As Integer
  Dim SheetThree As Integer
  
SheetOne = InputBox("What's the first sheet?")
SheetTwo = InputBox("What's the second sheet?")
SheetThree = InputBox("What's the third sheet?")
             

      
   With wdExl

Set cell_range = Range("B7:B14")

Dim Ano As Integer

SheetCount = .Worksheets.Count
.Worksheets.Add After:=.Worksheets(SheetCount)
 
 MsgBox ("SheetNo1 = " & SheetOne)
 
For Each Cell In cell_range

.Worksheets(SheetThree + 1).Cell.Value = .Worksheets(SheetOne).Cell.Value + .Worksheets(SheetTwo).Cell.Value + .Worksheets(SheetThree).Cell.Value
 
End With


Thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
.Worksheets(SheetThree + 1).Cell.Value ==> .Worksheets(SheetThree + 1).Range(Cell.Address).Value
 
Upvote 0
Set cell_range = Range("B7:B14")
This range is in activesheet of wdExl, not in Worksheets(SheetThree + 1). Is this correct? I think Worksheets(SheetThree + 1) is the newest sheet isn't it?

VBA Code:
Dim Ano As Integer

SheetCount = .Worksheets.Count
.Worksheets.Add After:=.Worksheets(SheetCount)
Set cell_range = Range("B7:B14")

MsgBox ("SheetNo1 = " & SheetOne)

For Each Cell In cell_range
    .Worksheets(SheetThree + 1).Cell.Value = .Worksheets(SheetOne).Range(Cell.Address).Value + .Worksheets(SheetTwo).Range(Cell.Address).Value + .Worksheets(SheetThree).Range(Cell.Address).Value
next
End With

And you need to put "Next" in front of End with.
 
Upvote 0
.Worksheets(SheetThree + 1).Range(Cell.Address).Value = .Worksheets(SheetOne).Range(Cell.Address).Value + .Worksheets(SheetTwo).Range(Cell.Address).Value + .Worksheets(SheetThree).Range(Cell.Address).Value
 
Upvote 0
Solution
.Worksheets(SheetThree + 1).Range(Cell.Address).Value = .Worksheets(SheetOne).Range(Cell.Address).Value + .Worksheets(SheetTwo).Range(Cell.Address).Value + .Worksheets(SheetThree).Range(Cell.Address).Value
Itworked! Thanks a lot :)
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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