Hi, at the bottom of my code there is private function sheet exists. What I would like is a sub that checks to see if the names of the existing sheets are reflected as text in the used range that is in the code above.
Basically if a name is entered in the range it creates a sheet, what I would like is for that sheet to be removed if the name is removed, so the code would need to constantly check that all sheets have a corresponding name in the used range, if not then sheet should be deleted.
Sheet1, Sheet2 and Sheet3 need to be exempt from being deleted.
I hope this makes sense.
Thanks
Basically if a name is entered in the range it creates a sheet, what I would like is for that sheet to be removed if the name is removed, so the code would need to constantly check that all sheets have a corresponding name in the used range, if not then sheet should be deleted.
Sheet1, Sheet2 and Sheet3 need to be exempt from being deleted.
I hope this makes sense.
Thanks
Code:
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993; background-color: #ffffff}span.s1 {color: #011993}span.s2 {color: #000000}</style>Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng1 As Range
Dim Rng2 As Range
Dim Rng3 As Range
Dim Rng4 As Range
Dim isect1 As Range
Dim isect2 As Range
Dim isect3 As Range
Dim isect4 As Range
If Target.Count > 1 Then Exit Sub
If Target.Address(False, False) = "C2" Then Call TitleCheck
If Target.Address(False, False) = "E2" Then Call TitleCheck
If Target.Address(False, False) = "H2" Then Call TitleCheck
Set Rng1 = Range("b11:h22")
Set Rng2 = Range("b26:h34")
Set Rng3 = Range("b38:h46")
Set Rng4 = Range("b50:h58")
Set isect1 = Intersect(Target, Rng1)
Set isect2 = Intersect(Target, Rng2)
Set isect3 = Intersect(Target, Rng3)
Set isect4 = Intersect(Target, Rng4)
If isect1 Is Nothing And isect2 Is Nothing And isect3 Is Nothing And isect4 Is Nothing Then Exit Sub
If Application.CountIf(ActiveSheet.UsedRange, Target.Value) = 1 Then
If SheetExists(Target.Value) = False Then
Application.ScreenUpdating = False
Set MyActiveCell = ActiveCell
Sheets("Timesheet").Cells.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Name = Target.Value
ActiveSheet.Range("A2").Select
Sheets("Labour Week").Activate
Application.Goto MyActiveCell
End If
End If
Application.ScreenUpdating = True
End Sub
Private Function SheetExists(SheetName As String) As Boolean
On Error Resume Next
SheetExists = (Worksheets(SheetName).Name = SheetName)
On Error GoTo 0
[COLOR=#011993][FONT=Menlo]End[/FONT][/COLOR][FONT=Menlo] [/FONT][COLOR=#011993][FONT=Menlo]Function[/FONT][/COLOR]