Macro for Sum of a value in a specific cell to value of a cell in another sheet

akrameldaly

New Member
Joined
Feb 14, 2024
Messages
17
Office Version
  1. 365
I have a workbook for daily report where each sheet in the workbook represents daily production records, i have used a formula on E7 = '1'!E7+'2'!$Q7, where '1' is the first day in the month and '2' is the 2nd day in the month and repeat this for each day till day the last day of the month by modifying the day number in the formula, now i need help to use a macro to solve this problem and run macro instead of repeating this task each day
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi so you need to sum different cells on different sheets ? ( E7 and Q7 in your example)?
 
Upvote 0
i have used a formula on E7 = '1'!E7+'2'!$Q7 ....
Welcome to the Forum!

E7 on sheet '1', and Q7 on sheet '2'. Which cell on sheet '3', sheet '4' etc? And how will the macro know this?

It would be much simpler if you could put your results in the same cell on each sheet. If your sheets '1' to '31' are in consecutive order, then you can simply use, for example:

=SUM('1:31'!A1)
 
Upvote 0
Welcome to the Forum!

E7 on sheet '1', and Q7 on sheet '2'. Which cell on sheet '3', sheet '4' etc? And how will the macro know this?

It would be much simpler if you could put your results in the same cell on each sheet. If your sheets '1' to '31' are in consecutive order, then you can simply use, for example:

=SUM('1:31'!A1)
Each day sum of the previous day like '2'E7 = '1'!E7+'2'!$Q7, '3' E7 = '2'!E7+'3'!$Q7, '4' E7 = '3'!E7+'4'!$Q7

E7 has the cumulative value.
Q7 has the day to day value
 
Upvote 0
And do you want the macro to populate these formulae? If so, try:

VBA Code:
Sub Test()

    Dim i As Long
    On Error Resume Next
    
    For i = 2 To 31
        Worksheets(CStr(i)).Range("E7").Formula = "=" & i - 1 & "!E7+Q7"
    Next i
    
    On Error GoTo 0

End Sub
 
Upvote 0
The result of !E7+Q7 is the same value as both cells from the same sheet it has to be from two different sheets E7 from the preceding sheet (i-1) andQ7 from the same sheet (i).
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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