This should work for the most part. Paste it into a workbook, save, and reopen. Then type anywhere in column A in worksheet 1. Note: Column B will need to be used as well. This code needs to keep track of the name the last time it did an update, so that when you delete a file it knows what file to delete and also if you make a name change.
Sub auto_open()
' Run the macro DidCellsChange any time a entry is made in a
' cell in Sheet1.
ThisWorkbook.Worksheets("Sheet1").OnEntry = "DidCellsChange"
End Sub
Sub DidCellsChange()
Dim KeyCells As String
' Define which cells should trigger the KeyCellsChanged macro.
KeyCells = "A1:A100"
' If the Activecell is one of the key cells, call the
' KeyCellsChanged macro.
If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
Is Nothing Then copysht
End Sub
Sub copysht()
Dim cl As Range
Col = 1
Row = 1
EmptySheets = 0
Do
If IsEmpty(Sheet1.Cells(Row, Col).Value) Then
If IsEmpty(Sheet1.Cells(Row, Col + 1).Value) Then
Else
Application.DisplayAlerts = False
Worksheets(Sheet1.Cells(Row, Col + 1).Value).Delete
Application.DisplayAlerts = True
Sheet1.Cells(Row, Col + 1).ClearContents
End If
EmptySheets = EmptySheets + 1
ElseIf IsEmpty(Sheet1.Cells(Row, Col + 1)) Then
Sheet2.Copy after:=Sheets(Row + 1 - EmptySheets)
ActiveSheet.Name = Sheet1.Cells(Row, Col).Value
Sheet1.Cells(Row, Col + 1) = Sheet1.Cells(Row, Col)
Else
If Sheet1.Cells(Row, Col + 1).Value = Sheet1.Cells(Row, Col).Value Then
'Nothing Changed
Else
Worksheets(Sheet1.Cells(Row, Col + 1).Value).Select
ActiveSheet.Name = Sheet1.Cells(Row, Col).Value
Sheet1.Cells(Row, Col + 1) = Sheet1.Cells(Row, Col)
End If
End If
Row = Row + 1
Loop Until Row >= 50
Sheet1.Select
End Sub
Bookmarks