Hi
I am using this macro to extract data from Master Sheet "Daily Data" to other worksheets:
What I am looking for is to add only new data into worksheets to prevent duplicate data.
Besides that, how can I prevent the creation of new worksheets if doesn't exist?
I only need add new data to existing worksheets, if column E has values without coincident worksheets, ignore them.
Any help would be appreciated
Regards
Lehoi
I am using this macro to extract data from Master Sheet "Daily Data" to other worksheets:
Code:
Sub SplitData()
Const NameCol = "E"
Const HeaderRow = 1
Const FirstRow = 2
Dim SrcSheet As Worksheet
Dim TrgSheet As Worksheet
Dim SrcRow As Long
Dim lastRow As Long
Dim TrgRow As Long
Dim Team As String
Application.ScreenUpdating = False
Set SrcSheet = ActiveWorkbook.Worksheets("Daily Data")
lastRow = SrcSheet.Cells(SrcSheet.Rows.Count, NameCol).End(xlUp).Row
For SrcRow = FirstRow To lastRow
Team = SrcSheet.Cells(SrcRow, NameCol).Value
Set TrgSheet = Nothing
On Error Resume Next
Set TrgSheet = Worksheets(Team)
On Error GoTo 0
If TrgSheet Is Nothing Then
Set TrgSheet = Worksheets.Add(After:=Worksheets(Worksheets.Count))
TrgSheet.name = Team
SrcSheet.Rows(HeaderRow).Copy Destination:=TrgSheet.Rows(HeaderRow)
End If
TrgRow = TrgSheet.Cells(TrgSheet.Rows.Count, NameCol).End(xlUp).Row + 1
SrcSheet.Rows(SrcRow).Copy Destination:=TrgSheet.Rows(TrgRow)
Next SrcRow
Application.ScreenUpdating = True
End Sub
What I am looking for is to add only new data into worksheets to prevent duplicate data.
Besides that, how can I prevent the creation of new worksheets if doesn't exist?
I only need add new data to existing worksheets, if column E has values without coincident worksheets, ignore them.
Any help would be appreciated
Regards
Lehoi