Macro for daily report

akrameldaly

New Member
Joined
Feb 14, 2024
Messages
17
Office Version
  1. 365
Hello,

I have a daily report on Excel which follows production figures and i need to make a macro to save time each day, the workbook represents a whole month and comprises of different worksheets each work sheet represents a day in the month starting from day 1 to day 31



Sheet 1

B4D4E4F4G4Q4
NO. OF HT
B7249052514136021
B825153979366021
B91334894949421
B101134531111814220
B11396433916433926

Sheet 2

D4E4F4G4Q4
NO. OF HT
B7251154616238121
B8253641811468121
B91336911511511521
B101136633213916320
B11398536018536026

Sheet 3

B4D4E4F4G4Q4
NO. OF HT
B7253156618240121
B8255643813470121
B91338913513513521
B101138635215918320
B11400538020538026

what i do is editing the formula for each worksheet as follows

D7 in sheet2 = 'sheet1'D7+Q7

I need to edit a macro to automate this work and to save time
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this macro, that presumes you will always have 21 sheets.

VBA Code:
Option Explicit

Sub SumAndTransferValues()
    Dim ws As Worksheet
    Dim i As Integer, j As Integer
    Dim lastSheet As Integer
    Dim sumRange As Range
    
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False

    lastSheet = ThisWorkbook.Worksheets.Count
    
    For i = 2 To 21
        Set ws = ThisWorkbook.Worksheets(i)
        
        For j = 7 To 11
            ws.Cells(j, 4).Value = ws.Cells(j, 4).Value + ThisWorkbook.Worksheets(i - 1).Cells(j, 4).Value
            ws.Cells(j, 5).Value = ws.Cells(j, 5).Value + ThisWorkbook.Worksheets(i - 1).Cells(j, 5).Value
            ws.Cells(j, 6).Value = ws.Cells(j, 6).Value + ThisWorkbook.Worksheets(i - 1).Cells(j, 6).Value
            ws.Cells(j, 7).Value = ws.Cells(j, 7).Value + ThisWorkbook.Worksheets(i - 1).Cells(j, 7).Value
        Next j
        
        For j = 7 To 11
            ws.Cells(j, 17).Value = Application.WorksheetFunction.Sum(ws.Range(ws.Cells(j, 4), ws.Cells(j, 7)))
        Next j
    Next i
    
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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