Explanation of VBA when fragrance is added
Everything is controlled by one procedure, which calls several other procedures:
(All procedures are in sheet "Lists" SHEET module)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or Target.Column <> 1 Or Target.Row = 1 Then Exit Sub
Dim rng As Range, cel As Range, ref As String, fragrance As String
Application.EnableEvents = False
'if fragrance deleted then delete the cell
If IsEmpty(Target) Then Target.Delete Shift:=xlUp: GoTo ErrorHandling
'remove spaces in fragrance
Target.Value = Replace(Target.Value, " ", "")
fragrance = Target.Value
Set rng = Range("fragrance")
'if new fragrance added, then test to see if name already exists
If ActiveSheet.Application.WorksheetFunction.CountIf(rng, fragrance) > 1 Then Call FragranceExists(Target, fragrance)
'now test to see if either or both required new sheets exist
Call DoSheetsExist(fragrance)
'now create 2 new sheets
Call AddSheets(fragrance)
'now format new sheets
Call FormatNewSheets(fragrance)
'create named range
Call AddNamedRange(fragrance)
'sort fragrance names alphabetically
Range("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes
ErrorHandling:
Err.Clear
Application.EnableEvents = True
End Sub
NOTE
refer to sheet "Lists" sheet module for the individual procedures
I have tried to put in notes where an explanation is required
Bookmarks