msquared99
Member
Here is the situation. I have a report that I run we will call "Report". I have a macro that opens the report once it is saved in its file location. The macro opens up a template called "Master Template". The "Master Template" spreadsheet has four tabs named Team 1, Team 2, Team 3 and, Team 4. Column B of the "Report" contains the names Team 1, Team 2, Team 3 and, Team 4.
My question is how do I change the macro (which works fine) below to copy all specific items named "Team X" from the "Report" into the matched tab name in the "Master Template"?
[pre]
[/pre]
Thanks for any help.
My question is how do I change the macro (which works fine) below to copy all specific items named "Team X" from the "Report" into the matched tab name in the "Master Template"?
[pre]
Code:
Sub SplitData()
Dim DataMarkers(), Names As Range, name As Range, n As Long, i As Long
'Find unique names
Set Names = Range("B2:B" & Range("B1").End(xlDown).Row)
n = 0
'Add worksheet for each unique name
For Each name In Names
If name.Offset(1, 0) <> name Then
ReDim Preserve DataMarkers(n)
DataMarkers(n) = name.Row
Worksheets.Add(After:=Worksheets(Worksheets.Count)).name = name
n = n + 1
End If
Next name
'Copy the unique data
For i = 0 To UBound(DataMarkers)
If i = 0 Then
Worksheets(1).Range("A2:Y" & DataMarkers(i)).Copy Destination:=Worksheets(i + 2).Range("A1")
Else
Worksheets(1).Range("A" & (DataMarkers(i - 1) + 1) & ":Y" & DataMarkers(i)).Copy Destination:=Worksheets(i + 2).Range("A1")
End If
Next i
End Sub
Here is the macro that opens the "Master Template".
Sub ChooseFile()
Dim fd As FileDialog
Dim FileName As String
Dim lastRow1 As Long ‘for use later
Dim lastRow2 As Long ‘for use later
Dim lastRow3 As Long ‘for use later
Dim lastRow4 As Long ‘for use later
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Get the number the button chosen.
Dim FileChosen As Integer
FileChosen = fd.Show
If FileChosen <> -1 Then
'Didn't choose anything (clicked cancel).
MsgBox "No file opened."
Exit Sub
Else
'Display name and path of file chosen.
FileName = fd.SelectedItems(1)
Workbooks.Open (FileName)
FileName = Mid(FileName, InStrRev(FileName, "") + 1, Len(FileName))
End Sub
Thanks for any help.