Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Compare Worksheet Names - Ignore Case?

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Compare Worksheet Names - Ignore Case?

One way:

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




In article ,
Trader_in_Paradise wrote:

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Compare Worksheet Names - Ignore Case?



"JE McGimpsey" wrote:

One way:

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




In article ,
Trader_in_Paradise wrote:

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.

Thank you, JE McGimpsey. UCase works perfectly. Thanks again.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Compare Worksheet Names - Ignore Case?

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.

"Trader_in_Paradise" wrote:



"JE McGimpsey" wrote:

One way:

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




In article ,
Trader_in_Paradise wrote:

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.

Thank you, JE McGimpsey. UCase works perfectly. Thanks again.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case Sensitive Compare, Lookup, etc???? GSkerm Excel Discussion (Misc queries) 5 October 23rd 07 04:08 AM
Compare Upper and Lower Case Zone Excel Discussion (Misc queries) 3 October 3rd 06 07:06 PM
How do I change the case from all caps to proper for names I have in columns E, F, G? duugg Excel Discussion (Misc queries) 22 April 26th 06 01:25 PM
Capital letters in names written by lower case vv Excel Programming 5 December 4th 05 08:34 PM
excel case changes on a column of first names jim_in_mich Excel Discussion (Misc queries) 2 March 31st 05 05:43 AM


All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"