Object Name

  • Thread starter Thread starter halem2
  • Start date Start date
H

halem2

The workbook starts with one sheet and using other code, I prompt use
to inser a new one. At that time the user input, which is the employe
number, is entered in a cell and the sheet name is changed to the em
code also.

when users enter emp codes, I need to validate if there already a shee
with the same emp code. Then I can pop up a msg telling the user tha
that emp code already exists
 
I only see your side of the thread, so I don't know if
anyone has suggested this, but here is some code you can
try:

'Assuming the emp number is in the variable EmpNumber
For Each ws In ThisWorkbook.Worksheets
If ws.Name = EmpNumber Then
MsgBox "The sheet named " & EmpNumber & " already
exists.", vbOKOnly + vbInformation, "Sheet Exists"
Exit Sub
Else
Sheets.Add
ActiveSheet.Name = EmpNumber
End If
Next ws

tod
 
Wouldn't this only work if there was no conflict or the conflicting name was
the first worksheet in the tab order?
 

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