bluepenink
Well-known Member
- Joined
- Dec 21, 2010
- Messages
- 585
Hi all
i have the below macro. it essentially copies data from "master" sheet into "template" and then creates seperate employee ID based sheets - exact copy of master except only containing the employee specific data.
it works fine, however, I am not sure how I can make it also take into account another extra row of data.
Can someone tell me how the logic is working here when it extracts the data to copy/paste i.e. how many rows it copy/paste?
</code>
i have the below macro. it essentially copies data from "master" sheet into "template" and then creates seperate employee ID based sheets - exact copy of master except only containing the employee specific data.
it works fine, however, I am not sure how I can make it also take into account another extra row of data.
Can someone tell me how the logic is working here when it extracts the data to copy/paste i.e. how many rows it copy/paste?
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Sub CreateSheets()
Dim ms As Worksheet
Dim ws As Worksheet
Dim sh As Worksheet
Dim cell As Range
Dim rng As Range
Dim oRange As Range
Application.ScreenUpdating = False
Set ms = ThisWorkbook.Sheets("Master")
Set ws = ThisWorkbook.Sheets("Template")
Set rng = ms.Range("A5:A" & ms.Cells(Rows.Count, 1).End(xlUp).Row)
For Each sh In ThisWorkbook.Worksheets
If sh.Name <> ms.Name And sh.Name <> "Template" Then
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
End If
Next sh
For Each cell In rng
If cell.Value = "" Then
If oRange Is Nothing Then Set oRange = cell Else Set oRange = Union(oRange, cell)
End If
Next cell
If Not oRange Is Nothing Then oRange.ClearContents
For Each cell In rng.SpecialCells(2).Areas
ws.Copy After:=ThisWorkbook.Sheets(Sheets.Count)
ActiveSheet.Name = ms.Range(Split(cell.Columns(3).Offset(1).Address, ":")(1)).Value
cell.Resize(cell.Rows.Count + 1, cell.Columns.Count + 9).Copy
ActiveSheet.Range("A5").PasteSpecial xlPasteAll
Application.Goto ActiveSheet.Range("A1")
Next cell
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Last edited: