Compare Worksheet Names - Ignore Case?

T

Trader_in_Paradise

Dim MyName As String
Dim MySheet As Object
Set MySheet = ActiveWorkbook.ActiveSheet
Dim Sheet As Object
On Error GoTo btnRename_Err:
....(Other Code)
NamingRoutine:
Else
For Each Sheet In ActiveWorkbook.Sheets
If MyName = Sheet.Name Then MsgBox "This Sheet Name is already in
use. Please pick another name.", , "This Worksheet Name is in Use."
Next Sheet
GoTo NamingRoutine:
.....(Other Code)
This Code fails if MyName and Sheet.Name are the same except for
capitalization.
For Example: If MyName = Hello and Sheet.Name = hello, the code fails. It
generates the MsgBox "This Sheet Name..." and loops endlessly.

Can I convert MyName and Sheet.Name to upper case, then Compare?
Other Suggestions? Thank you.
 
J

JLatham

One "error" I've seen more than once was someone spelling a sheet name with
an extra space either at the beginning or the end (usually at right end) and
you can modify what JE gave you to handle even that:

If UCase(Trim(MyName)) = UCase(Trim(Sheet.Name)) Then...

and if you hate those big clunky UPPERCASE characters, you can always use
LCase instead of UCase <g>.
 

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

Top