G
Guest
I am writing code to rename sheets with the text entered in cells B1
1. I am
trying to handle 2 cases. First where the user types in the text one cell at
a time and second where the user pastes in several cells at a time. The
pasting part seems to work but when I enter data one cell at a time and hit
"Enter" it works but if I hit "TAB" to move to the next cell it fails becuase
the selection is now in the next cell...
Here is my code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
If Intersect(Range("B1
1"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Row = 1 Then
For Each Target In Selection
If SheetExists(Target.Value) Then
MsgBox "Sheet Name " & Target.Value & " already used!",
vbCritical, "Duplicate Sheet Name Error"
Application.EnableEvents = False
Application.Undo
Else
Select Case Target.Column
Case 2
Sheet2.Name = Target.Value
Case 3
Sheet3.Name = Target.Value

trying to handle 2 cases. First where the user types in the text one cell at
a time and second where the user pastes in several cells at a time. The
pasting part seems to work but when I enter data one cell at a time and hit
"Enter" it works but if I hit "TAB" to move to the next cell it fails becuase
the selection is now in the next cell...
Here is my code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
If Intersect(Range("B1

Application.EnableEvents = False
If Target.Row = 1 Then
For Each Target In Selection
If SheetExists(Target.Value) Then
MsgBox "Sheet Name " & Target.Value & " already used!",
vbCritical, "Duplicate Sheet Name Error"
Application.EnableEvents = False
Application.Undo
Else
Select Case Target.Column
Case 2
Sheet2.Name = Target.Value
Case 3
Sheet3.Name = Target.Value