VBA amateur here, I am writing a code to automate some processes in my workplace, i am however stuck in trying to overwrite all contents from workseets of the same name from one workbook to another.
My current process is as follows.
- I store the macro in workbook 1
- I open the worksheet which i wish to run the macro on
- I run the macro
- Ideally the macro should run the code below onto every worksheet and following which overwrite the data of a similar worksheet name in my master workbook. It is likely to be 40 different sheets with static worksheet name.
example: copy contents in worksheet("Asia") of workbook A into worksheet("Asia") of master workbook.
Please advise if this can be done in vba.
I tried looking up solutions on this site but is unable to find a solution.
Dim wk As Worksheet
For Each wk In ActiveWorkbook.Worksheets
wk.Activate
Dim TR As Integer
TR = Range("S" & Rows.Count).End(xlUp).Row
Range("Z4").Formula = "=CONCATENATE(TEXT(D4,""mm/dd/yyyy""),S4,M4)"
Range("Z4").Copy
Range("Z4:Z" & TR).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Dim UR As Integer
UR = Range("S" & Rows.Count).End(xlUp).Row
Range("AA4").Formula = "=CONCATENATE(TEXT(D4,""mm/dd/yyyy""),S4,F4)"
Range("AA4").Copy
Range("AA4:AA" & UR).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Dim DR As Integer
DR = Range("S" & Rows.Count).End(xlUp).Row
Range("AB4").Formula = "=CONCATENATE(TEXT(A4,""mm/dd/yyyy""),S4,K4)"
Range("AB4").Copy
Range("AB4:AB" & DR).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Dim FR As Integer
FR = Range("S" & Rows.Count).End(xlUp).Row
Range("AC4").Formula = "=CONCATENATE(TEXT(A4,""mm/dd/yyyy""),S4,K4)"
Range("AC4").Copy
Range("AC4:AC" & FR).PasteSpecial xlPasteAll
Application.CutCopyMode = False
ActiveSheet.Range("A1").Value = Date
ActiveSheet.Range("A1").Formula = "=TEXT(TODAY(),""dd/mm/yyyy"")"
Last = Cells(Rows.Count, "A").End(xlUp).Row
For j = Last To 1 Step -1
If ActiveSheet.Cells(j, 1) > ActiveSheet.Range("A1") Then
ActiveSheet.Cells(j, 29).FormulaR1C1 = "=CONCATENATE(RC[-10], RC[-18])"
End If
Next j
Next wk
End Sub
My code for the spreadsheet above work, i am just figuring out how i can update the data in my master workbook.