Searching for worksheet

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I am using Excel 97.

Can anyone assist me please?

I am wanting some code which with the use of an input box
searches all the worksheets in a workbook for a sheet
with that value.

A user can enter either a name of a numerical value and
the worksheets are checked, if no worksheet is found then
a new sheet is created with the name of the value of the
input box.

I have something similar in place at the moment but it
doesn't always work correctly as some of the worksheets
have similar names!

Any offers?

Thanks


Mark
 
mark copy the code into this post so that we can have a look it may just
be simple case of change part of the code,

Save all of us a bit of time
 
blnExists = False
For a = 1 To Sheets.Count
If Sheets(a).Name = strInputName Then blnExists = True
Next
If blnExists = False Then
Sheets.Add
Sheets(Sheets.Count).Name = strInputName
Else
Sheets(strInputName).Select
End If

Cheers,

Jeff
 
Not sure if it's clear or not that strInputName is what your InputBox
returns.

Jeff
 
Here's my code:

Sub GoToBadge()

NameNumber = InputBox(prompt:="Enter Name or Number")
On Error GoTo NewName
' this on error causes a fail to find to go to create a
new record
Worksheets(NameNumber).Activate
' this find goes to first empty cell in leave record
FindEmptyCell
Exit Sub

NewName:
On Error GoTo FINISH
If DialogSheets("GetNumDialog").Show Then
EmpType
Newsheet = ActiveSheet.Name
Worksheets(Newsheet).Name = NameNumber
Cells(4, "C").Value = NameNumber
OfficerName = InputBox(prompt:="Enter Name")
Cells(4, 1).Value = FullName
StartDate = InputBox(prompt:="Enter Date Joining,
DD/MM/YYYY")
Cells(2, 2).Value = CDate(StartDate)
Resume
Else
End If
FINISH:
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top