Hi jordon1214,
Replace my existing code with this (post back if you're not sure how to do):
Option Explicit
Sub Macro1()
'Written by Trebor76
'Visit my website www.excelguru.net.au
Dim varMyTabLen As Variant
Dim lngStartRow As Long
Dim lngMyRow As Long
Dim rngCell As Range
Application.ScreenUpdating = False
lngStartRow = 2 'Initial data row. Change to suit.
For Each rngCell In Sheets("Database").Range("A" & lngStartRow, Sheets("Database").Range("A" & Rows.Count).End(xlUp))
'Clear any existing data to prevent data duplication
On Error Resume Next
varMyTabLen = Len(Sheets(CStr(rngCell)).Name)
If Err.Number = 0 Then 'Only try and clear any existing entries if the tab exists
If WorksheetFunction.CountA(CStr(rngCell)) > 0 Then
If Sheets(CStr(rngCell)).Range("A:E").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row >= 2 Then
Sheets(CStr(rngCell)).Range("A" & lngStartRow & ":E" & Sheets(CStr(rngCell)).Range("A:E").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row).ClearContents
End If
End If
End If
Err.Clear
On Error GoTo 0
Next rngCell
For Each rngCell In Sheets("Database").Range("A" & lngStartRow, Sheets("Database").Range("A" & Rows.Count).End(xlUp))
'Populate tabs
On Error Resume Next
varMyTabLen = Len(Sheets(CStr(rngCell)).Name)
If Err.Number = 0 Then 'Only populate sheets if the tab exists
If WorksheetFunction.CountA(CStr(rngCell)) = 0 Then
Sheets(CStr(rngCell)).Range("A" & lngStartRow & ":E" & lngStartRow).Value = Sheets("Database").Range("B" & rngCell.Row & ":F" & rngCell.Row).Value
Else
lngMyRow = Sheets(CStr(rngCell)).Range("A:E").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Sheets(CStr(rngCell)).Range("A" & lngMyRow & ":E" & lngMyRow).Value = Sheets("Database").Range("B" & rngCell.Row & ":F" & rngCell.Row).Value
End If
End If
Err.Clear
On Error GoTo 0
Next rngCell
Application.ScreenUpdating = True
MsgBox "Process is complete"
End Sub
Robert
Bookmarks