I could do with some help as struggling with switching between sheets. I'm trying to write a code which:
1. If the data is for a new person is create a spreadsheet with their name and adds a groupnamed tab
2. If not a new person, then adds a new group in the existing sheet after the last group name
3. Copies the data from the master workbook template sheet into the current group tab (in new or existing sheet) and saves
4. If the next person is different then it closes the sheet
5. Returns to the master sheet
I would be really grateful if someone could help me solve this.
Thanks
James
Dim Person as String
Dim LastPerson as String
Dim NextPerson as String
Dim LastGroup as String
Dim Group as String
Dim Outputs as workbook
Dim Inputs as Workbook
Set Outputs = activeworkbook
If lastperson <> Person Then
Workbooks.Add
Fname = "Z:\November 2012\" & Person & ".xlsx"
ActiveWorkbook.SaveAs Filename:=Fname
Set Inputs = ActiveWorkbook
ActiveSheet.Name = Group
End If
If lastperson = Person Then
Inputs.Activate
Sheets.Add(After:=Sheets(LastGroup)).Name = group
End If
With outputs
.Activate
.Sheets("Template").Cells.Select
.Sheets("Template").Copy Destination:=Inputs.Sheets(group).Paste
End With
Inputs.Save
If Person <> NextPerson Then
Inputs.Close
End If
outputs.Activate
Bookmarks