I can't get this to work. I have the following code on my sheet which executes when cells are changed. If the user enters values in B3 or D3 the sheet renames itself to the value that is in that cell.
I ran into an issue if a sheet by that name already exists. so I added the code in bold I found elsewhere on this site. However it keeps exectuing the code in italics when there is a duplicate sheet already in the workbook and I can't see why.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim wsSheet As Worksheet
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
'add date when user is selected
If Target.Column = 2 And Target.Row = 2 Then
If Target <> "" And Target.Offset(, 2).Value = "" Then
Target.Offset(, 2) = Date
Else
Target.Offset(, 2) = ""
End If
End If
'delete location when pallet entered
If Target.Column = 2 And Target.Row = 3 Then
If Target <> "" Then
Target.Offset(, 2) = ""
On Error Resume Next
Set wsSheet = Sheets(Cells(3, 2).Value)
On Error GoTo 0
'determining if the worksheet name already exists
If Not wsSheet Is Nothing Then
ActiveSheet.Name = InputBox("Sheet", "Enter Sheet Name", Cells(3, 2).Value)
Else
ActiveSheet.Name = "Pallet " & Cells(3, 2).Value
Exit Sub
End If
End If
End If
Basically I want the sheet name to change to what the type in Cell B3. If a sheet with that name exists I want it to pop an input box with the Sheet name in it so they can add a -1, -2, --3 to it and hit ok and get that sheet name.
I ran into an issue if a sheet by that name already exists. so I added the code in bold I found elsewhere on this site. However it keeps exectuing the code in italics when there is a duplicate sheet already in the workbook and I can't see why.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim wsSheet As Worksheet
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
'add date when user is selected
If Target.Column = 2 And Target.Row = 2 Then
If Target <> "" And Target.Offset(, 2).Value = "" Then
Target.Offset(, 2) = Date
Else
Target.Offset(, 2) = ""
End If
End If
'delete location when pallet entered
If Target.Column = 2 And Target.Row = 3 Then
If Target <> "" Then
Target.Offset(, 2) = ""
On Error Resume Next
Set wsSheet = Sheets(Cells(3, 2).Value)
On Error GoTo 0
'determining if the worksheet name already exists
If Not wsSheet Is Nothing Then
ActiveSheet.Name = InputBox("Sheet", "Enter Sheet Name", Cells(3, 2).Value)
Else
ActiveSheet.Name = "Pallet " & Cells(3, 2).Value
Exit Sub
End If
End If
End If
Basically I want the sheet name to change to what the type in Cell B3. If a sheet with that name exists I want it to pop an input box with the Sheet name in it so they can add a -1, -2, --3 to it and hit ok and get that sheet name.