Validation of a Sheet Name already existing in a workbook

  • Thread starter Thread starter DoctorV
  • Start date Start date
D

DoctorV

I have the following code that works fine except for the line
If Sheets.Name = Sheets("MainForm").Range("b18").Value Then


What I want is to validate that if an existing Sheet name matches th
value in Sheets("MainForm").Range("b18").Value to give them a messag
box and cancel the sub.
What is the proper syntax to refer to check if a sheet name exists

Thanks a lot!!!


ActiveSheet.Protect DrawingObjects:=False, Contents:=False
Scenarios:=False
If Sheets.Name = Sheets("MainForm").Range("b18").Value Then
MsgBox "Sheet already exists"
Cancel = True
Else
Sheets("AllData").Select
Sheets("AllData").Copy Before:=Sheets(1)
Sheets("AllData (2)").Select
Sheets("AllData (2)").Name = Sheets("MainForm").Range("b18").Value
ActiveSheet.Activate
Application.Goto Reference:="R2:R64000"
Selection.ClearContents
Sheets("MainForm").Select
Range("A2").Select
'End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True
Scenarios:=True :
 
Hi
try something like
If lcase(activesheet.Name) =
lcase(Sheets("MainForm").Range("b18").Value)
 
Frank,
Thanks for replying. The problem is I need to check the name of EVER
worksheet tab in the Workbook, not just the Active Sheet
Thanks DoctorV;
 
Hi
in this case try something like the following:
sub foo()
dim wks as worksheet
dim wks_name

wks_name=Sheets("MainForm").Range("b18").Value
on error resume next
set wks = worksheets(wks_name)
on error goto 0
if not wks is nothing then
msgbox "worksheet already exists"
exit sub
end if
activesheet.name=wks_name
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