Rename Sheets but.....
Target is passed in as the range of cells that triggered the event. Best to
not try to change it as a matter of practice (it is byval, so it does no
damage). But using it as the cells to loop through avoids your problem.
Rarely is is appropriate to use selection in sheet event unless the code is
managing the selection (IMO).
If you Undo on a multicell paste - is that what you want to do? I would
guess not.
Private Sub Worksheet_Change(ByVal Target As Range)
dim cell as Range
On Error GoTo ErrorHandler
If Intersect(Range("B1:P1"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Row = 1 Then
For Each Cell in Target
If SheetExists(cell.Value) Then
MsgBox "Sheet Name " & cell.Value & " already used!",
vbCritical, "Duplicate Sheet Name Error"
Application.EnableEvents = False
'Application.Undo
' cell.clearcontents perhaps
Else
Select Case cell.Column
Case 2
Sheet2.Name = cell.Value
Case 3
Sheet3.Name = cell.Value
|