I am trying to create a Macro that pastes code from one workbook into a list of other workbooks. It's become a bit too complicated.
There is a folder containing many sheets, and rather than update them all individually, I want to be able to copy and paste a few new rows at the end of each one automatically.
In short, there is a Workbook called "Setup.xlsm" in which the cells to be copied and pasted are in range H10:M21 in the sheet "Pupils"
Also in the Workbook called "Setup.xlsm" is a list of all the names of the workbooks needing to be updated. These appear in column B in the sheet "Staff"
The copied cells need to be pasted into column A in each of these workbooks. The user defines which row to paste them in at. The row number is stored in cell M8 inthe "Pupils" sheet of the "setup.xlsm" sheet
The macro will be started from sheet "Setup.xlsm" sheet "Pupils". I need it to open each of the destination workbooks in turn, unprotect it, copy and paste the cells from the other workbook, reprotect the destination workbook, save it and close it.
Sorry the code below might be a bit of a mess, I have been experimenting so much with things I found on Google that I am all mixed up
Sub February()
Dim i As Integer
Dim j As Integer
Dim Subfolder As String
Dim SubfolderSubjNom As String
Dim Targetfile As String
Dim SubjFile As String
Dim wbk As Workbook
Sheets("Staff").Select
Subfolder = ActiveSheet.Range("G1").Value
SubfolderSubjNom = Subfolder & "SubjectNominations\"
i = 1
j = ActiveSheet.Range("M8").Value
Do While Workbooks("Setup.xlsm").Sheets("Staff").Cells(i, 2).Value <> Empty
SubjFile = SubfolderSubjNom & Workbooks("Setup.xlsm").Sheets("Staff").Cells(i, 2).Value & ".xlsm"
Set wbk = Workbooks("Setup.xlsm")
With wbk.Sheets("Pupils")
Range("H10:M21").Copy
End With
Set wbk = Workbooks.Open(SubjFile)
With wbk.Sheets("Nominations")
ActiveSheet.Unprotect
Range("A" & j & ":F" & j + 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A2").Select
Workbook.Save
Workbook.Close
End With
Loop
End Sub
Bookmarks