C
Craig Brandt
HI All:
I have this working in one workbook, but when I transplant it into another,
it fails to function as expected.
Issue: I would like to check my current workbook to ensure that a sheet does
not exist, before trying to create it.
In a UserForm, I allow the user to input a sheet name that they would like
to import. Upon their depressing the "AddListBut" on the userform (ListForm)
it checks to ensure the user put something in the Listbox "NewListName" then
check to see if the worksheet already exists.
Public ShtName as String
Private Sub AddListBut_Click()
If ListForm.NewListName = "" Then MsgBox ("Missing ""New List Name"""): Exit
Sub
' Check to see if requested sheet name is already present
ShtName = ListForm.NewListName
On Error Resume Next
Set SH = Worksheets(ShtName)
On Error GoTo 0
If Not SH Is Nothing Then MsgBox ("Sheet Already Exists. "): Exit Sub
' Sheet not there, Continue
..
..
..
..
If the user adds new sheets, everything works correctly. the first time the
user types in a name that already exists, it gives them the " Sheet already
exists" message, but when they go back in and types a new name, it
consistantly informs them that the sheet already exists, even if it is
untrue.
Any ideas?
Craig
I have this working in one workbook, but when I transplant it into another,
it fails to function as expected.
Issue: I would like to check my current workbook to ensure that a sheet does
not exist, before trying to create it.
In a UserForm, I allow the user to input a sheet name that they would like
to import. Upon their depressing the "AddListBut" on the userform (ListForm)
it checks to ensure the user put something in the Listbox "NewListName" then
check to see if the worksheet already exists.
Public ShtName as String
Private Sub AddListBut_Click()
If ListForm.NewListName = "" Then MsgBox ("Missing ""New List Name"""): Exit
Sub
' Check to see if requested sheet name is already present
ShtName = ListForm.NewListName
On Error Resume Next
Set SH = Worksheets(ShtName)
On Error GoTo 0
If Not SH Is Nothing Then MsgBox ("Sheet Already Exists. "): Exit Sub
' Sheet not there, Continue
..
..
..
..
If the user adds new sheets, everything works correctly. the first time the
user types in a name that already exists, it gives them the " Sheet already
exists" message, but when they go back in and types a new name, it
consistantly informs them that the sheet already exists, even if it is
untrue.
Any ideas?
Craig