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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This is one method. Paste in a regular module :

VBA Code:
Option Explicit

Sub celCopyAdd()
    Sheets("Sheet2").Range("D7") = Sheets("Sheet1").Range("D7") + Sheets("Sheet1").Range("Q7")
End Sub
 
Upvote 0
thanks for your answer
This line will work for only "sheet2"
what i need is a code to work for all sheets from sheet1 to sheet31
 
Upvote 0
You'll need to explain in more detail what you are needing. I understand you want the macro to work on all 31 sheets but explain in further detail what
should occur on each of those sheets.
 
Upvote 0
When i run the macro i need the value of the previous sheet to be added to the value in the Q column cells in the running sheet
e.g. 'sheet(N)'D7='sheet(N-1)'D7+'sheet(N)'Q7
 
Upvote 0
See if this works for you :

VBA Code:
Sub CalculateFromPreviousSheet()
    Dim ws As Worksheet
    Dim prevWs As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
        If Not ws.Index = 1 Then
            Set prevWs = ThisWorkbook.Worksheets(ws.Index - 1)
            ws.Range("D7").Value = prevWs.Range("D7").Value + ws.Range("Q7").Value
        End If
    Next ws
End Sub
 
Upvote 0
Thank you again

Ok now that works for only cell D7, i need it to work on all the cells in the table range "D7:G11"
i tried to write this line but it doesn't works

ws.Range("D7:D11").Value = prevWs.Range("D7:D11").Value + ws.Range("Q7:Q11").Value

it gives Run-time error '13' type mismatch
 
Upvote 0
See if this works ...

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
    
    lastSheet = ThisWorkbook.Worksheets.Count
    
    For i = 2 To lastSheet
        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
End Sub
 
Upvote 0
No, it doesn't work it tooks 5 minutes to run and at the end gives error 13 type mismatch any way thank you for your response :)
 
Upvote 0
Hmmm ... it does run here as expected.

Can you post your wotkbook to a cloud site (DropzBox, etc) so I can download and see what is going on ?
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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